Form email plugin

aje

Member
Have been trying different ways here without any luck. I am making an order form there people are ordering a free catalog from different stores. I have 2 lists (db)

db store
id
date
storename
email

db catalogorder
id
date
name
adress
postcode
city
storename (dbjoin value=id label=storename (from db store))

When people order a catalog i need the email form plugin get the email adress from db store. Please help, i am really stuck
 
Use the email to (eval) with something like
Code:
$storeid = '{catalogorder___storename_raw}';
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
    ->select('email')
    ->from('store')
    ->where('id= ' . $db->quote($storeid));
$db->setQuery($query);
$storeemail = $db->loadResult();
return $storeemail;
 
  • Like
Reactions: rob
Nice :) Worked like a charm. Is it also possible to show a description field from the store db in the order message ?
 
I am gonna go out on a limb as i just got this one working myself...

Code:
$storeid = '{catalogorder___storename_raw}';

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
  ->select(array('email', 'description'))
  ->from('store')
  ->where('id= ' . $db->quote($storeid));
$db->setQuery($query);
$rowdata = $db->LoadObject();

$email = $rowdata->email;
$description = $rowdata->description;

Just use $email and $description wherever you need them.
 
I put the code in Email to (eval) but cant get to work in the Message Text. Any suggestions?
 
Is there another way to do this ? Need a field from another table to show in the message.
 
Yes it can be done, as long as you have a common field in the current form that allows you to lookup and match the row in the other table. What is the table name in the current form that we can use to lookup with?
 
as Troester says you would need to write a PHP template, using the code provided by prophoto. That should give you two variables '$email' and '$description' which you can then echo out in the template:

PHP:
<?php
$storeid = '{catalogorder___storename_raw}';

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
  ->select(array('email', 'description'))
  ->from('store')
  ->where('id= ' . $db->quote($storeid));
$db->setQuery($query);
$rowdata = $db->LoadObject();

$email = $rowdata->email;
$description = $rowdata->description;
?>

This is your email's content - where you can add the <?php echo $email;?> and the <?php echo $description;?>
 
Last edited by a moderator:
Have made an php template and used the placeholders and get the info from the form. I cant get the sql lookup to work. Have tried to get the fields from the "Email to (eval)" into the template, no luck. I tried with the php plugin into the template, no luck and last i tried to get it to work with an sql from the php template.

my sql looks like this
$storeid = '{katbestillinger___bkforhandler_raw}';
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select(array('fhepost', 'fhutalternativ'))
->from('forhandlere')
->where('id= ' . $db->quote($storeid));
$db->setQuery($query);
$rowdata = $db->LoadObject();

$email = $rowdata->fhepost;
$description = $rowdata->fhutalternativ;

return $email;

Is it possible to write an sql directly in the php template and how ?
 
Rob forgot that placeholders don't work in PHP templates, as we don't eval them, we include them. So instead of ...

Code:
$storeid = '{katbestillinger___bkforhandler_raw}';

... you'd need ...

Code:
$storeid = $emailData['katbestillinger___bkforhandler_raw'];

Other than that, do what Rob said. So don't "return" anything. Just echo $email and $description in the template, as per Rob's example.

-- hugh
 
do i run this from "email to" form plugin or from the template. Where comes the $emailData from ?
 
The reason i used return email was because it returned my email to adress. Itsw only the description field i need to output in the email message.
 
The "Email to (eval)" and PHP template are two separate things. The code will look similar, but in the email eval, just look up return the email. In the PHP template, as per Rob's code, look up the variable(s) you need, and then echo them in the actual body of the template.

-- hugh
 
Cant get it to work. is it possible i can send you the file ? now i get an error "Champ 'Array' inconnu dans where clause SQL=SELECT fhepost,fhutalternativ FROM forhandlere WHERE id= Array"

When i used the $storeid = '{katbestillinger___bkforhandler_raw}'; as before i got no errors but no output either.

Sql:
<?php
$storeid = $emailData['katbestillinger___bkforhandler_raw'];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select(array('fhepost', 'fhutalternativ'))
->from('forhandlere')
->where('id= ' . $db->quote($storeid));
$db->setQuery($query);
$rowdata = $db->LoadObject();

$email = $rowdata->fhepost;
$description = $rowdata->fhutalternativ;
?>

output in the body
<h4>epost:_<?php echo $email;?>beskrivelse<?php echo $desription;?></h4>
 
Try this ...

Code:
$storeid = $emailData['katbestillinger___bkforhandler_raw'];
$storeid = $storeid[0];

To answer a previous question you asked, $emailData is set up in the plugin code just before we include the PHP template file:

Code:
    protected function _getPHPTemplateEmail($tmpl)
    {
        $emailData = $this->data;
        $formModel = $this->getModel();

        // Start capturing output into a buffer
        ob_start();
        $result = require $tmpl;
        $message = ob_get_contents();
        ob_end_clean();

        if ($result === false)
        {
            return false;
        }

        return $message;
    }

(around line 475 in ./plugins/fabrik_form/email/email.php)

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top