当客户通过联系表 7 提交电子邮件时,如何检查电子邮件是否已存在于我的数据库中并将通知消息更改为“您的电子邮件已存在于我们的数据库中”
到目前为止,我已经尝试使用 before_send 挂钩,但是当我单击提交时,页面只是挂起并且没有确认消息。
下面是我的functions.php中的函数
add_action( 'wpcf7_before_send_mail', 'check_email' );
function check_email( $cf7 )
{
$email = $cf7->posted_data["email"];
if($email == 'Is in our database'){
echo ('Your email exists in our database');
}
}
感谢您的帮助
我在验证上添加了一个过滤器:
add_filter( 'wpcf7_validate', 'email_already_in_db', 10, 2 );
function email_already_in_db ( $result, $tags ) {
// retrieve the posted email
$form = WPCF7_Submission::get_instance();
$email = $form->get_posted_data('your-email');
// if already in database, invalidate
if( email_exists( $email ) ) // email_exists is a WP function
$result->invalidate('your-email', 'Your email exists in our database');
// return the filtered value
return $result;
}
在本例中,电子邮件字段被命名为your-email
.
功能email_exists
是一个原生 WP 函数来处理这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)