I found a solution! I added an input field called receiverEmail and added
for it in my .css-file (it has a double function: serving as anti spam field and for inserting the email adress on the server).
[[!FormIt?
&hooks=`contactAdressInput,email`
&emailTo=`[[+receiverEmail]]`
&emailToName=`[[+receiver]]`
&validate=`receiver:required, receiverEmail:blank`
]]
<select name="receiver">
<option value="John" [[!+fi.receiver:FormItIsSelected=`John`]]>John</option>
<option value="Jane" [[!+fi.receiver:FormItIsSelected=`Jane`]]>Jane</option>
</select>
<input type="email" name="receiverEmail" />
Now you still need a snippet (I called it contactAdressInput) to insert the email adress:
switch($hook->getValue('receiver')) {
case 'John':
$hook->setValue('receiverEmail','[email protected]');
break;
case 'Jane':
$hook->setValue('receiverEmail','[email protected]');
break;
default:
return false;
}
return true;
One thing to mention: The
documentation states:
Snippets should return true on success. On failure, the snippet can set error messages in the hook object's errors variable and return false. In either case, hooks listed after the custom hook in the &hooks parameter will not execute.
So if I understand that right it should not work. But it does. At least for me.