同时存储联系人表单7值为什么我在mysql中获取空值

时间:2016-06-06 13:29:19

标签: php mysql

我已使用以下代码插入(联系form7)表单的数据,但在mysql表中,表单字段填充为“NULL”。

function contactform7_before_send_mail( $form_to_DB ) {

global $wpdb;

$form_to_DB = WPCF7_Submission::get_instance();

if ( $form_to_DB ) {
$formData['posted_data'] = $form_to_DB->get_posted_data();
}

$name =$formData['posted_data']['name'];
$mail =$formData['posted_data']['e_mail'];
echo($name);
print_r($_POST['name']);
$wpdb->insert( 'wp_cf7_test', array( 'name' => $name ,'e_mail' => $mail) );

}
remove_all_filters ('wpcf7_before_send_mail');
add_action( 'wpcf7_before_send_mail', 'contactform7_before_send_mail' );

1 个答案:

答案 0 :(得分:0)

我读了你的问题。我也面临这个问题。您编写的此代码属于联系表单版本7 3.9.Up联系表单7 3.9可以。 你使用下面的代码。这可能是工作

function contactform7_before_send_mail( $form_to_DB ) {

global $wpdb;

$form_to_DB = WPCF7_Submission::get_instance();

if ( $form_to_DB ) {
$formData = $form_to_DB->get_posted_data();
}

$name =$formData['name'];
$email =$formData['email'];
$subject=$formData['subject'];
$message=$formData['message'];



//$wpdb->insert( 'wp_cf7_test', array( 'name' => $name ), array( '%s' ) );
    $wpdb->insert( 'wp_cf7_test2', array( 'name' =>             
     $name,'email'=>$email,'subject'=>$subject,'message'=>$message,'file'=>$file,'    date' => date('Y-m-d H:i:s') ), array( '%s','%s','%s','%s','%s','%s') );

}
remove_all_filters ('wpcf7_before_send_mail');
add_action( 'wpcf7_before_send_mail', 'contactform7_before_send_mail' );