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(),
)
);
}
}
Leave a Reply