【发布时间】:2021-01-06 23:58:29
【问题描述】:
我正在使用联系表 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 my_validate_email($result, $tag) {
$formName = 'email_form'; // Change to name of the form containing this field
$fieldName = 'email_123'; // Change to your form's unique field name
$errorMessage = 'Email has already been submitted'; // Change to your error message
$name = $tag['name'];
if ($name == $fieldName) {
if (is_already_submitted($formName, $fieldName, $_POST[$name])) {
$result->invalidate($tag, $errorMessage);
}
}
return $result;
}
如果用户在 24 小时后重试,我们现在需要允许重复输入。
我们的建议是运行一个 cron 作业来标记超过 24 小时的条目,然后允许用户继续。我们添加了一个新的表列 (allow_duplicate) 来标记条目。
任何关于如何构建 functions.php 验证的建议将不胜感激。
【问题讨论】:
-
是您在电子邮件中检查的唯一字段吗?
-
是的,但架构足够灵活,我可以更改它。有什么原因吗?
-
只是想另一种方法来做到这一点。使用瞬变代替 CFDB
-
我对瞬变不熟悉。然而,在这一点上的任何建议都将非常有价值
标签: database wordpress validation duplicates contact-form-7