php - Contact Form 7: use hook created using wpcf7_before_send_mail for only one contact form by id -


i working on site several forms created using contact form 7. 1 of these forms, passing variables collected using hidden input field in form. passing these variables email using wpcf7_before_send_mail hook, these values passing every email (i added dynamic variables static text) here's code:

add_action( 'wpcf7_before_send_mail', 'wpcf7_add_text_to_mail_body' );   function wpcf7_add_text_to_mail_body($contact_form){      $values_list = $_post['valsitems'];      $values_str = implode(", ", $values_list);       // mail property      $mail = $contact_form->prop( 'mail' ); // returns array        // add content email body      $mail['body'] .= 'industries selected';      $mail['body'] .= $values_list;        // set mail property changed value(s)      $contact_form->set_properties( array( 'mail' => $mail ) );   } 

i trying figure out how pass these values 1 of contact form email templates, via form id.

contact form 7 uses hidden input type store form id. uses hidden field name _wpcf7. can form id way.

$form_id = $contact_form->posted_data['_wpcf7']; 

so final code should be

add_action( 'wpcf7_before_send_mail', 'wpcf7_add_text_to_mail_body' );  function wpcf7_add_text_to_mail_body($contact_form){  $form_id = $contact_form->posted_data['_wpcf7'];  if ($form_id == 123): // 123 => form id.      $values_list = $_post['valsitems'];      $values_str = implode(", ", $values_list);       // mail property      $mail = $contact_form->prop( 'mail' ); // returns array        // add content email body      $mail['body'] .= 'industries selected';      $mail['body'] .= $values_list;        // set mail property changed value(s)      $contact_form->set_properties( array( 'mail' => $mail ) );  endif;  } 

hope helps.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -