• Resolved lobert

    (@lobert)


    Hi,

    Great plugin! I have a select menu with 4 options, lets say: option 1, option 2 etc. Based on what option is chosen in the form I need the form to be sent to a different recipient. So if option 1 is chosen, send to [email protected] and if option 2 is chosen, send to [email protected]

    I cant quite figure out how I could change the notification recipient based on a select menu option – any thoughts on how to set this up?

    Thanks

    Rob

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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:

    [email protected] : Option 1
    [email protected] : 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

    Plugin Author fabianlindfors

    (@fabianlindfors)

    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( '[email protected]', '[email protected]', '[email protected]' );
      }
    
      if ( 'option_2' == $field_value ) {
        return array( '[email protected]', '[email protected]' );
      }
    
      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( '[email protected]', '[email protected]', '[email protected]' );
    }

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Email recipient based on select option’ is closed to new replies.