2013-05-28 29 views
2

我已经想使用此代码保存在数据库联系表格7插件的字段值:如何在数据库中保存Contact Form 7插件的字段值?

add_action('wpcf7_before_send_mail', my_conversion($cf7)); 

function my_conversion($cf7) 
{ 
    $name = $cf7->posted_data["your-name"]; 
    $email = $cf7->posted_data["your-email"]; 
    $Work = $cf7->posted_data["tel-Work"];  
    $homenumber = $cf7->posted_data["homenumber"]; 
    $mobilenumber = $cf7->posted_data["mobilenumber"]; 

    mysql_query("INSERT INTO `hello` (`Your Name`, `Work`, `Home`, `Mobile No`, `Email`) VALUES ('$name',$Work,$homenumber,$mobilenumber,$email)");  
} 

,但其没有工作,这里的错误:

"`$cf7->posted_data["...."]`;" can not fetch values. 

回答

0

你要跟应该尝试使用WP准备查询的,而不是直接查询

$name = $cf7->posted_data["your-name"]; 
$work = $cf7->posted_data["tel-Work"]; 

$email = $cf7->posted_data["your-email"]; 

$wpdb->query($wpdb->prepare( 
    " 
     INSERT INTO $wpdb->hello 
     (contact, email , name) 
     VALUES (%d, %s, %s) 
    ", 
     $work, 
    $email , 
    $name 
)); 
+0

谢谢你的帮助,但当我使用你的插入查询是这样的: $ wpdb-> query($ wpdb-> prepare(“INSERT INTO $ wpdb-> hello(Your Name,Work,Home,Mobile No ,电子邮件)VALUES(%s,%d,%d,%d,%s)“,$ fname,$ work,$ homenumber,$ mobilenumber,$ email)); 我得到这个错误: “调用一个非对象的成员函数query()” – user2293520

2

这是错误的:

add_action('wpcf7_before_send_mail', my_conversion($cf7));

它应该是:

add_action('wpcf7_before_send_mail', 'my_conversion'); 

要知道什么样的价值观是你$cf7对象可用,在你my_conversion函数的开头添加var_dump($cf7);。请使用mysql_query!改为使用WPDB Class

最后,有Flamingo Plugin它提交后自动保存您的表单。

相关问题