admin管理员组

文章数量:1315287

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this 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.
{
}
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this 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.
{
}
Share Improve this question edited Nov 26, 2020 at 14:49 Howdy_McGee 20.9k24 gold badges91 silver badges177 bronze badges asked Nov 26, 2020 at 14:40 user14633289user14633289 11 bronze badge 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 – user14633289 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
Add a comment  | 

1 Answer 1

Reset to default 1

Try this:

// Get current form.
$wpcf7      = WPCF7_ContactForm::get_current();
$contact_form_id = $wpcf7->id;

本文标签: plugin contact form 7Set id of cf7 in the data save function