Guardar datos contac form 7 en base de datos
add_action('wpcf7_before_send_mail', 'save_form' );
function save_form( $wpcf7 ) {
global $wpdb;
/*
Nota: desde la version 3.9 Contact Form 7 ha eliminado $wpcf7->posted_data
y ahora se accede a los datos a través de API.
*/
$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 . 'tps_forms',
array(
'form' => $submited['title'],
'data' => serialize( $data ),
'date' => date('Y-m-d H:i:s')
)
);
}
CREATE TABLE `wp_tps_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;