Suppose you want to send the form submission email conditionally, based on a form input.
For example, there is a ‘department’ drop down in the form. Depending on the selection in the drop down, the email should be sent to the corresponding address. (firstname.lastname@example.org, email@example.com etc)
The current version of Simfatic Forms (3.2) does not have the feature to set a condition for sending the email.
However, we have extension modules for rescue. Extension modules can be used to extend or change the behavior of the server side script. (See: extension modules in Simfatic Forms help.)
First, we need a place-holder email address in the ‘recipients’ list
In the setting above, firstname.lastname@example.org is the place-holder email.
The extension module
The extension module is written in PHP. Download the sample extension module here.
You can edit the extension module in any text editor.
Here is how it works:
The extension module overrides call-back function BeforeSendingFormSubmissionEMail(). When the script is sending the form submission email, it will call BeforeSendingFormSubmissionEMail() , for each of the recipients. Here, we can change the recipient address, just before the email is sent.
We check the selected value of the ‘department’ drop down and update the recipient to the corresponding email:
The code is not that complicated.
if(false !== strpos($receipient,’Admin’))
//Admin gets all the emails!
elseif(false !== strpos($receipient,’email@example.com’))
$dept = $this->formvars['Department'];
$receipient = ‘Sales<firstname.lastname@example.org>’;
$receipient = ‘Service<email@example.com>’;
$receipient = ‘Technical<firstname.lastname@example.org>’;
$receipient = ‘Billing<email@example.com>’;
You can edit the extension module and customize it for your needs.
Loading the extension module
First, enable extension modules in the ‘form processing options’ page.
Then, in the extension modules page, press the ‘Add module’ button and select the extension module (edited and made ready – above)
Proceed to ‘take the code’ page and upload the form.
The .zip file contains the extension module and a Simfatic Forms template file of the form used to create and test this extension module.