hello who can help me i can not retrieve the data of the selection field in my database. That's what I do following this example Saving contact form 7 data into custom db and not wordpress db but it doesn't work
- I create the table
CREATE TABLE test(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
city VARCHAR(50)
);
- I Create the form in CF7
[select city "New York" "Miami" "London"]
[submit "OK"]
- And here is the code in function.php
function contactform7_before_send_mail( $form_to_DB ) {
//connexion to database
$mydb = new wpdb('locacarm_rent2','Sam2005','locacarm_rent2','localhost');;
$form_to_DB = WPCF7_Submission::get_instance();
if ( $form_to_DB )
$formData = $form_to_DB->get_posted_data();
$city = $formData['city'];
$mydb->insert( 'test', array('city' =>$city ), array('%s') );
}
remove_all_filters ('wpcf7_before_send_mail');
add_action( 'wpcf7_before_send_mail', 'contactform7_before_send_mail' );