To save submitted data to the database, you need to follow the bellow steps
Create a table to store the data in the database.
1 2 3 4 5 6 7 |
CREATE TABLE `bm_wpcf7_forms` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `form` varchar(100) NOT NULL DEFAULT '', `data` text NOT NULL, `date` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; |
Add the bellow code to your themes functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
add_action('wpcf7_before_send_mail', 'bm_save_form' ); function bm_save_form( $wpcf7 ) { global $wpdb; /* Note: since version 3.9 Contact Form 7 has removed $wpcf7->posted_data and now we use an API to get the posted data. */ $submission = WPCF7_Submission::get_instance(); if ( $submission ) { $submited = array(); $submited['title'] = $wpcf7->title(); $submited['posted_data'] = $submission->get_posted_data(); } $data = array( 'name' => $submited['posted_data']['name'], 'email' => $submited['posted_data']['email'] ); $wpdb->insert( $wpdb->prefix . 'bm_wpcf7_forms', array( 'form' => $submited['title'], 'data' => serialize( $data ), 'date' => date('Y-m-d H:i:s') ) ); } |
WordPress: Contact Form 7, save form submited data to the database