Wordpress Hooks

WordPress hook to Save contact form 7 data into custom db

Wordpress hook to Save contact form 7 data into custom db

wordpress
446Views

Hello, welcome to therichpost.com. In this post, I will tell you, WordPress hook to Save contact form 7 data into custom db. WordPress is the best cms. WordPress hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress. Now I am going to tell you how the hooks work.

Here is the Wordpress hook to Save contact form 7 data into custom db and you also need to make custom database to custom data and you need to add this wordpress hook into your wordpress theme’s functions.php file: 
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' );

 There are so many hooks in wordpress and i will let you know all. Please do comment if you any query related     to this post. Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

2 Comments

Leave a Reply

Positive SSL