web and mobile development, UIUX designing, WordPress website developers

How Contact Form submitted data into a table in WordPress(WPCF7)

The code below shows when Contact Form 7 is submitted data is inserted into a table in WordPress. In function.php, place this code.

add_action('wpcf7_before_send_mail','save_form');
function save_form( $wpcf7 ){
global $wpdb;
$submission = WPCF7_Submission::get_instance();//get form data
if ($submission){
$submited = array();
$submited['title'] = $wpcf7->title();
$submited['posted_data'] = $submission->get_posted_data(); //get submitted data
 }
if(!empty($submited)){
$current_uid = get_current_user_id();
$wpdb->insert( $wpdb->prefix.'events',//table name events
 array( 
 'name'      =>$submited['posted_data']['your-name'], //identifier for name provided in wpcf7
 'email'     =>$submited['posted_data']['your-email'], //identifier for email provided in wpcf7
 'invoice'   =>$submited['posted_data']['invoice'], //identifier for invoice provided in wpcf7
 'uid'      =>$current_uid,  'timestamp' =>time(), 
)
 ); 
 }
}
Contact Form inserted data into a table in WordPress

Recent Blogs


Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

To Know Us Better

Browse through our work.

Explore The Technology Used

Learn about the cutting-edge technology and techniques we use to create innovative software solutions.