I’m scratching my head a bit with a FormIt issue. I’ve got this form with a dropdown, and I want the selected option to determine which email address the form gets sent to.
am I allowed to use conditional logic (like output modifiers) directly within the &emailTo parameter?
What is the placeholder [[+recipient]] and where does it get set?
If it gets set in a snippet that is executed before the FormIt snippet, then it could work.
If you mean the placeholder [[!+fi.recipient]] that gets set by FormIt, then you can’t use it here (as FormIt hasn’t been executed).
Personally, I would write a custom hook snippet that runs before the “email” hook and sets the value of “emailTo” ($hook->formit->config['emailTo']) according to the value of the recipient parameter ($hook->getValue('recipient')).
Thank you for your reply.
I’m going to try this snippet and see if it works
<?php
// Get the value of the recipient from the submitted form
$recipient = $hook->getValue('recipient');
// Set the email recipient based on the dropdown value
switch ($recipient) {
case 'option1':
$emailTo = 'one@example.com';
break;
case 'option2':
$emailTo = 'two@example.com';
break;
case 'option3':
$emailTo = 'three@example.com';
break;
default:
$emailTo = 'other@example.com'; // Default email address
break;
}
// Set the emailTo parameter for FormIt
$hook->formit->config['emailTo'] = $emailTo;
return true;
If this is a simple contact form, you might look at SPForm. It has the multiple recipients drop-down built in, and I’ve found it to be more spam-proof than FormIt, even without Captcha.