如何检查数据库中是否存在通过联系表7提交的电子邮件? [英] How do I check if email submitted via Contact form 7 exists in my database?

查看:95
本文介绍了如何检查数据库中是否存在通过联系表7提交的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当客户通过联系表7提交电子邮件时,如何检查数据库中是否已存在该电子邮件,并将通知消息更改为您的电子邮件已存在于我们的数据库中



到目前为止,我已经尝试过使用before_send挂钩,但是当我单击提交时,页面只是挂起,没有确认消息。



下面是我函数中的函数.php

  add_action('wpcf7_before_send_mail','check_email'); 

函数check_email($ cf7)
{
$ email = $ cf7-> posted_data [ email];
if($ email ==‘是在我们的数据库中’){
echo(您的电子邮件在我们的数据库中存在);
}
}

感谢您的帮助

解决方案

我在验证时添加了一个过滤器:

  add_filter('wpcf7_validate','email_already_in_db',10,2); 

函数email_already_in_db($ result,$ tags){
//检索已发布的电子邮件
$ form = WPCF7_Submission :: get_instance();
$ email = $ form-> get_posted_data(‘您的电子邮件’);
//如果已经在数据库中,则使
if(email_exists($ email))// // email_exists是一个WP函数
$ result-> invalidate('your-email','Your电子邮件存在于我们的数据库中);
//返回过滤后的值
return $ result;
}

在这种情况下,电子邮件字段的名称为 email



函数 email_exists 是用于处理此问题的本机WP函数。 / p>

When customer submits email via contact form 7, how do I check if email already exists in my database and change notification message to "Your email already exists in our database"

So far I have tried using before_send hook, but when I click submit, the page just hangs and no confirmation message.

Below is the function I have in my 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');
}
}

Thanks for your help

解决方案

I've added a filter on validation:

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;
}

In this case the email field is named your-email.

The function email_exists is a native WP function to handle this.

这篇关于如何检查数据库中是否存在通过联系表7提交的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆