联系表7,保存选定选项(下拉菜单)到数据库
我正在尝试保存到我的数据库,即我的联系表7表格中的提交。我发现了一些功能(不知道作者)。它有效,但不能保存从下拉菜单中选择的选项到数据库。我不知道我缺少什么。我尝试了这一点:
add_action("wpcf7_submit", "SE_379325_forward_cf7", 10, 2);
function SE_379325_forward_cf7($form, $result) {
if( !class_exists('WPCF7_Submission') )
return;
$submission = WPCF7_Submission::get_instance();
if ($result["status"] == "mail_sent") { // proceed only if email has been sent
$posted_data = $submission->get_posted_data();
save_posted_data($posted_data);
}
};
// your insert function:
function save_posted_data($posted_data){
$form_id = $posted_data["_wpcf7"]; // this is the post->ID of the submitted form so if you have more than one you can decide whether or not to save this form fields
if($form_id == 403)
return;
global $wpdb;
$wpdb->insert(
$wpdb->prefix.'tabletest',
array(
'lastname'=>$posted_data['lastName'],
'name'=>$posted_data['firstName'],
'email'=>$posted_data['email'],
'phone'=>$posted_data['tel-3'],
'subject'=>$posted_data['menu-338'],
'role'=>$posted_data['menu-761'],
'message'=>$posted_data['your-message'],
'thedate'=>$posted_data['date-288']
),
array('%s')
);
}
我无法保存的字段是“主题”和“角色”。它们只是在我的表列上空的。
这是我从联系表7 这是我的表格
。
I am trying to save to my database, the submissions from my contact form 7 form. I found some functions (don't know the author) to do so. It works, but it won't save the option selected from the drop-down menus to the database. I don't know what I am missing. I tried this:
add_action("wpcf7_submit", "SE_379325_forward_cf7", 10, 2);
function SE_379325_forward_cf7($form, $result) {
if( !class_exists('WPCF7_Submission') )
return;
$submission = WPCF7_Submission::get_instance();
if ($result["status"] == "mail_sent") { // proceed only if email has been sent
$posted_data = $submission->get_posted_data();
save_posted_data($posted_data);
}
};
// your insert function:
function save_posted_data($posted_data){
$form_id = $posted_data["_wpcf7"]; // this is the post->ID of the submitted form so if you have more than one you can decide whether or not to save this form fields
if($form_id == 403)
return;
global $wpdb;
$wpdb->insert(
$wpdb->prefix.'tabletest',
array(
'lastname'=>$posted_data['lastName'],
'name'=>$posted_data['firstName'],
'email'=>$posted_data['email'],
'phone'=>$posted_data['tel-3'],
'subject'=>$posted_data['menu-338'],
'role'=>$posted_data['menu-761'],
'message'=>$posted_data['your-message'],
'thedate'=>$posted_data['date-288']
),
array('%s')
);
}
The fields I cannot save are 'subject' and 'role'. They are just empty on my table columns.
This is my form from Contact Form 7
I would appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个潜在的问题。
提交
函数中获取$ contact_form-> id
将其传递给您的功能。我也添加了消毒,您可以根据需要进行更改。默认情况下,CF7不会对数据进行消毒,因为它只是输入/输入输出,并且不会存储任何地方。
Two potential problems.
$contact_form->id
in the firstsubmit
function.I've added sanitization as well, you can alter as needed. CF7 Doesn't by default sanitize data since it's just input in/input out, and not stored anywhere.