conditions for form email plugin

von Horst

Member
using a contact form here:
http://kuenburg.org/kontakt

there is a dropdown. ist it possible to use email form plugin, so that this email is sent to a different email-address depending on the dropdown selection?

eg:

Can this be done by conditions on form email plugin? how would the syntax be?


thanks! :)
 
Yes this can be done on the 'Email to' field with the email plugin.

You can use placeholders, so something like {kontakt___Betreff} should work. Just put that into your Email to field.
 
Felikat - I think the email addresses aren't stored in the form, but what von Horst wants to do is:

if dropdown value == 'Konzerte' then email to hans@keunburg.org
if dropdown value == 'Ausstellungen' then email to sepp@keunburg.org

You could use the condition field in the email plugin but that would then require setting up 2 plugins.

A simpler way would be to use the 'email to eval' option with some code similar to this:

PHP:
if ('{kontakt___Betreff}' == 'Konzert') {
  return 'hans@kuenburg.org';
} elseif ('{kontakt___Betreff}' == 'Ausstellungen') {
  return 'sepp@kuenburg.org';
}
return 'default@kuenburg.org';
 
I've done this for quite a few sites recently.

My recommendation is to use a separate table and a join element for the 'contacts' rather than a simple dropdown. In the table, you'd have a normal primary key 'id', the label you want to use for the dropdown, and the email for the contact. So just create this as a simple Fabrik list, and add your 'title' and 'email' elements as simple field elements. Then change the Betreff dropdown on your main form to be a join to it.

Then you can write your 'email to (eval)' code in a totally maintenance free way, such that if you add more options, or change the email contact addresses, you don't need to go back and modify your PHP. So assuming you had a join element to a table called 'contacts' which has 'id' and 'email':

PHP:
$my_email_to = '';
$contact_id = (int)$formModel->getElementData('kontakt___Betreff', true, 0);
if (!empty($contact_id)) {
   $myDb = $formModel->getListModel()->getDb();
   $query = $myDb->getQuery(true);
   $query->select('email')->from('contacts')->where('id = ' . $myDb->Quote($contact_id));
   $myDb->setQuery($query);
   $email_to = $myDb->loadResult();
}
return $my_email_to;

This assumes your new 'contacts' table is on the same database as the table for the form being submitted. Obviously change the table and email column name to suit.

This way, you can manage your contact list through a simple Fabrik form / list, and not need to twiddle with PHP when it changes.

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

Thank you.

Members online

Back
Top