0

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.
{
}
3
  • 1
    I'm not sure what you mean by "mix" but this might be a better question asked on the Contact Form 7 forums so that it can be answered by people who are familiar with the plugin.
    – Howdy_McGee
    Commented Nov 26, 2020 at 14:50
  • @Howdy_McGee pass only the id of the specific form to the code above which will have to save the data in a custom table Commented Nov 26, 2020 at 14:59
  • Questions exclusively regarding 3rd party plugins is considered to be off-topic and better asked using their respective support methods. Please take the tour and visit our help center to learn more. A better place to ask this type of question may be The Official WordPress Forums or the plugin specific support.
    – Howdy_McGee
    Commented Nov 26, 2020 at 15:09

1 Answer 1

1

Try this:

// Get current form.
$wpcf7      = WPCF7_ContactForm::get_current();
$contact_form_id = $wpcf7->id;
2
  • how to specify the precise id by hand passing the number? Commented Nov 26, 2020 at 14:53
  • Not sure what you mean. If you want specific from ID to pass by hand ( I guess you mean manually) then you can simply/directly pass the ID of your choice to the variable e.g. $form_id = 123;
    – Awais
    Commented Nov 26, 2020 at 15:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.