php - 使用自定义响应联系表 7 将用户提交限制为每个用户一个
问题描述
我正在开发一个多语言竞赛网站,用户只能注册一次。我正在使用带有CFDB 插件的联系表 7。使用CFDB作者提供的以下代码,该函数检查表单是否已经提交;
function is_already_submitted($formName, $fieldName, $fieldValue) {
require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
$exp = new CFDBFormIterator();
$atts = array();
$atts['show'] = $fieldName;
$atts['filter'] = "$fieldName=$fieldValue";
$atts['unbuffered'] = 'true';
$exp->export($formName, $atts);
$found = false;
while ($row = $exp->nextRow()) {
$found = true;
}
return $found;
}
以及验证表单的以下代码,确保没有重复的电子邮件(这就是我打算检测重复用户的方式)
function one_user_per_contest($result, $tag) {
$formName = array('Contest Form', 'Contest form ES'); // This is the form name for English and spanish
$fieldName = 'your-email'; // Name of the field to validate, which is the email field
$errorMessage = "you've signed up already"; // error message
$name = $tag->name;
if ($name == $fieldName) {
if (is_already_submitted($formName, $fieldName, $_POST[$name])) {
$result->invalidate($tag, $errorMessage);
}
}
return $result;
}
add_filter('wpcf7_validate_email*', 'one_user_per_contest', 20, 2);
此验证工作正常,因为它不允许重复电子邮件,但我面临的问题是我希望得到一些指导,我希望将错误消息显示为响应。而不是回应说One or more fields have an error. Please check and try again.
,我想让它说you've signed up already
[见下图];
谢谢
解决方案
推荐阅读
- angular - 有条件地改变组件的动画
- python - 更改 urllib2 的 Header 以在 google 上获得不同的搜索结果
- react-native - 默认内容类型不会替换为 axios 中用于上传图像的反应本机应用程序中的新内容类型(表单数据)
- flutter - 在flutter中从rest api获取特定用户的数据
- python - Python Behave 在 except 上引发测试失败
- javascript - 预加载 Google 字体和 CLS
- java - 何时使用 deflate() 的 deflateroutputstream?
- c# - 修改存储在 AsyncLocal 中的对象
- javascript - 如何保存在同一画布上绘制的多个基本形状,并像在油漆中一样预览?
- winapi - CryptVerifyMessageSignature 返回带有附加标头的原始消息,为什么?