Trouble with Formit &emailTo and Dropdown Selection

Hi there.

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?

<form action="[[~[[*id]]]]" method="post">
    <label for="recipient">Choose a recipient:</label>
    <select name="recipient">
        <option value="option1">Option 1</option>
        <option value="option2">Option 2</option>
        <option value="option3">Option 3</option>
        <option value="option4">Option 4</option>
    <label for="message">Your Message:</label>
    <textarea name="message"></textarea>
    <input type="submit" value="Send">

    &emailSubject=`New Message from Website`

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')).

1 Like

Thank you for your reply.
I’m going to try this snippet and see if it works

// 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 = '';
	case 'option2':
		$emailTo = '';
	case 'option3':
		$emailTo = '';
		$emailTo = ''; // Default email address

// Set the emailTo parameter for FormIt
$hook->formit->config['emailTo'] = $emailTo;

return true;

emailSelectTo + emailSelectField properties are possible. The usage is described well in the docs.

1 Like

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.

1 Like

@jako Thank you, I can’t believe I went through the docs and I missed that …

@bobray thanks, I will check out SPForm.

By the way, it seems the snippet worked.