Hi Rob,
I can think of a couple of ways, you could have your select values set as the email address and the labels showing the options like:
option1@email.com : Option 1
option2@email.com : Option 2
Then in the email notifications you can set it against this value.
An alternative would be having a hidden email field, that JS sets the value based on the value of the option, bit more work involved in this and more maintenance if new options are added.
Thread Starter
lobert
(@lobert)
Hi,
Thanks for the suggestion. When you say “Then in the email notifications you can set it against this value.” what do you mean exactly – do you mean under “Send to” choose “select from field” and choose the select menu as the recipient field?
One concern I have with this option is that I actually have 3 email accounts to send to if option 1 is chosen and 4 emails if option 2 is chosen so not sure how you could add multiple emails as a select value.
Thanks
Rob
Hi! Thank you James for helping out.
The way James is suggesting (with a select field) is very nice but won’t work if you are planning on sending to multiple recipients. To achieve this you would have to write a tiny bit of code using the af/form/email/recipient filter. Here’s an example:
function form_email_recipients( $recipients ) {
$field_value = af_get_field( 'field_name' );
if ( 'option_1' == $field_value ) {
return array( 'address1@test.com', 'address2@test.com', 'address3@test.com' );
}
if ( 'option_2' == $field_value ) {
return array( 'address4@test.com', 'address5@test.com' );
}
return $recipients;
}
add_action( 'af/form/email/recipient/key=FORM_KEY', 'form_email_recipients' );
Don’t forget to replace FORM_KEY with your form key.
Hope this helps! 🙂
Thread Starter
lobert
(@lobert)
Hi Fabian,
That worked! Thanks very much. I actually had to send emails based on 2 select menu option so used this:
//the recipient
$recipient = af_get_field( 'recipient' );
//the email subject
$subject = af_get_field( 'subject_email' );
if ( 'feedback' == $subject && 'singapore' == $recipient ) {
return array( 'name1@email.com', 'name2@email.com', 'name3@email.com' );
}
Perhaps I should start another topic.. Having csv export of entries would be great. I know I can export entries but my clients arent able to do that. Even if you added this to the paid version I’d be happy to buy!
Thanks