• Resolved gestad2019

    (@gestad2019)


    I try to dynamically set the recipient of a form according to the value of a drop down. I found this code that seems to be outdated and also other posts related to the syntax for this code. It sends the e-mail to ‘else’ conditions regardless of the option selected.

    I couldn’t find documentation on the docs.
    What is the new way of getting the posted data?

    if ( $posted_data['enquiry-type'] == 'Option A' ) { // If General option is selected
    $recipient_email = '[email protected]';
    }
    elseif ( $posted_data['enquiry-type'] == '
    Option B' ) { // else if Media option is selected
    $recipient_email = 'yyy@mail.fr';
    }
    elseif ( $posted_data['enquiry-type'] == 'Option C' ) { // else if Jobs option is selected
    $recipient_email = 'zzz@mail.fr';
    }
    else { // If no dropdown option is selected
    $recipient_email = '[email protected]';
    }

    // set the email address to recipient
    $mailProp = $contact_form->get_properties(‘mail’);
    $mailProp[‘mail’][‘recipient’] = $recipient_email;

    // update the form properties
    $contact_form->set_properties(array(‘mail’ => $mailProp[‘mail’]));

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thread Starter gestad2019

    (@gestad2019)

    add_action( 'wpcf7_before_send_mail',
      function( $contact_form, &$abort, $submission ) {
    
       $posted_data = $submission->get_posted_data( 'enquiry-type' );
       $posted_data = implode( ', ', (array) $posted_data );
    
       if ( $posted_data == 'Option A' ) { 
          $recipient_email = '[email protected]';
       }
       elseif ( $posted_data == 'Option B' ) { 
          $recipient_email = '[email protected]';
       }
       elseif ( $posted_data == 'Option C' ) { 
          $recipient_email = '[email protected]';
       }
       else { // If no dropdown option is selected
          $recipient_email = '[email protected]';
       }
    	
       $mailProp = $contact_form->get_properties('mail');
       $mailProp['mail']['recipient'] = $recipient_email;
    
       $contact_form->set_properties(array('mail' => $mailProp['mail']));
       },
    	10, 3
    );

    Thanks for your answer, this is what works for me to conditionally change the recipient according to the value of a drop-down field.
    Using CF7 5.7.6 on WP 6.2

    • This reply was modified 1 year, 10 months ago by gestad2019.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘New syntax for $posted_data’ is closed to new replies.