php - 联系表 7 - wpcf7_before_send_mail 和 wpcf7_submit 的问题
问题描述
我目前正在一个网站上工作,该网站有用户通过使用 Contact Form 7 创建的表单提交。我正在尝试将其扩展到记录该活动(日期/时间、登录用户、从填写的字段中获取信息),并且我有尝试了很多次和方法来使用钩子 wpcf7_before_send_mail 和 wpcf7_submit 但似乎都没有工作。表单提交,但下面的代码没有运行。我什至尝试手动输入信息(表名、用户 ID、客户等)以查看它是否会提交,但仍然没有。
以下是我用来将一些信息保存到我希望将活动存储在其中的数据库的当前代码:
add_action('wpcf7_before_send_mail', 'save_in_database');
function save_in_database($data) {
global $wpdb;
$account_number = get_account_number();
$department = get_user_role();
if ($data->title == 'Social_Media_Tool_Form'){
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$cf7_data = $submission->get_posted_data();
$name = $cf7_data['customer-name'];
}
}
$activity_table_name = $wpdb->prefix .'_'. $account_number . '_activity_log';
//Creates activity log
$wpdb->insert($activity_table_name, array(
'date' => current_time('Y-m-d H:i:s'),
'user_id' => get_current_user_id(),
'customer_name' => $name,
'activity_type' => 'social',
'department' => $department
));
}
我之前使用过相同的代码来记录其他活动,所以理论上它应该在这里工作。
我目前使用 Wordpress 5.1 并使用 Contact Form 7 5.1.1
解决方案
我弄清楚了这个问题。在表单上,您必须将“subscribers_only: true”添加到其他设置中。因为这没有设置,所以它不允许我从当前用户那里提取信息,这就是它没有提交到数据库的原因。
推荐阅读
- ruby-on-rails - 如何将 CoreUI 合并到 React Rails 应用程序中?
- machine-learning - 如何调试数学方程的实现
- objective-c - NSDocument 窗口关闭后如何释放内存?
- firebase - 在 Firebase 实时规则中翻转 OR 条件返回错误访问
- python - 使用 python 客户端使用客户端证书访问 K8S API
- javascript - Firebase 托管上的 MP4 视频在 Chrome 上不规则地加载
- bash - bash 函数中的 printf 向 `wc -l` 结果添加新行
- javascript - 如何在 Stencil.JS Web 组件中创建输入掩码?
- bash - shell 变量的名称可以包含空格吗?
- php - 如何将这种类型的数组转换为列表?