Set id of cf7 in the data save function [closed]

Question

My goal is to save the data sent by the cf7 module inside a table external to those created by wordpress I found this procedure:

  1. Create Custom table

    CREATE TABLE candidate(
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(50)
    );

  2. Create contact form 7 fields

    [text* title]
    [submit "Send"]

  3. Add Below code to function.php

      function contactform7_before_send_mail( $form_to_DB ) {
         //set your db details
         $mydb = new wpdb('root','','cistom_db','localhost');
    
         $form_to_DB = WPCF7_Submission::get_instance();
         if ( $form_to_DB ) 
             $formData = $form_to_DB->get_posted_data();
         $title = $formData['title'];
    
         $mydb->insert( 'candidate', array( 'title' =>$title ), array( '%s' ) );
     }
     remove_all_filters ('wpcf7_before_send_mail');
     add_action( 'wpcf7_before_send_mail', 'contactform7_before_send_mail' );
    

all clear and simple, however, I was wondering how to mix the specific id of the cf7 module?

$form_id = $contact_form->id();
if ($form_id == 2654 ) // 123 => Your Form ID.
{
}
0
user14633289 2 months 0 Answers 10 views 0

Leave an answer