检查电子邮件是否存在时不显示jQuery验证消息 [英] jQuery validation message not displaying while checking the email exist or not

查看:82
本文介绍了检查电子邮件是否存在时不显示jQuery验证消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery验证程序来验证表单.我正在检查电子邮件ID在数据库中是否已经存在或是否正常运行.我在Network->Response tab中得到输出.

I am using jQuery validator for validation the form.I am checking the email id is already exist or not in the database which is working perfectly. I am getting output in the Network->Response tab.

问题是我无法在表单中显示该验证错误消息.我还设置了消息规则,但未显示.

The issue is I am not able to display that validation error message in the form. I also set the message rule but that is not displaying.

您能帮我这个忙吗? 检查下面的图像.

Would you help me out in this? Check below image.

表格

<form name="form1" method="post" action="demo1.php">
  <input type="text" name="name" id="name" placeholder="name"><br />
  <input type="email" name="email" id="email" placeholder="email"><br />
  <input type="text" name="mobile" id="mobile" placeholder="mobile no"><br />
  <input type="submit" name="submit" value="submit">
</form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods.min.js"></script>
<script  src="assets/js/test.js"></script>

test.js

// When the browser is ready...
  $(function() {
    $("form[name='form1']").validate({
      // Specify the validation rules
      rules: {
        name:{
          required: true,
          minlength: 3,
          maxlength: 50
        },
        email: {
          required: true,
          email: true,
          remote: {
            url: "process?key=emailalready_register",
              type: "post"
            }
          },
          mobile: {
            required: true,
            number: true,
            minlength: 10,
            maxlength: 10
          }
        },
        messages: {
          email: {remote: "Email already in use!"}
        },
        submitHandler: function(form) {
        form.submit();
      }           
    });    
  });

Process.php

function emailalready_register($conn){
  if(isset($_POST['email'])) {
    $email =$conn->real_escape_string(trim($_POST['email']));
    $sql_check_email="SELECT email FROM register WHERE email =?";
    $stmt = $conn->prepare($sql_check_email);
    $stmt->bind_param("s", $email);
    $stmt->execute();
    $stmt->bind_result($email);
    $rows = $stmt->fetch();
    $total_rows = count($rows);
    if( $total_rows > 0 ){
      echo 'Already exsist';
    } else {
      echo 'Not exsist';
    }
    $stmt->close();
    $conn->close();
  }   
}

推荐答案

尝试一下:-

$(function() {
    $("form[name='form1']").validate({
      // Specify the validation rules
      rules: {
        name:{
          required: true,
          minlength: 3,
          maxlength: 50
        },
        email: {
          required: true,
          email: true,
          remote: "process?key=emailalready_register",

          },

          mobile: {
            required: true,
            number: true,
            minlength: 10,
            maxlength: 10
          }
        },
        messages: {
          email: {remote: "Email already in use!"}
        },
        submitHandler: function(form) {
        form.submit();
      }           
    });    
  });

处理.php

function emailalready_register($conn){
  if(isset($_POST['email'])) {
    $email =$conn->real_escape_string(trim($_POST['email']));
    $sql_check_email="SELECT email FROM register WHERE email =?";
    $stmt = $conn->prepare($sql_check_email);
    $stmt->bind_param("s", $email);
    $stmt->execute();
    $stmt->bind_result($email);
    $rows = $stmt->fetch();
    $total_rows = count($rows);
    if( $total_rows > 0 ){
      echo 'false';
    } else {
      echo 'true';
    }
    $stmt->close();
    $conn->close();
  }   
}

这篇关于检查电子邮件是否存在时不显示jQuery验证消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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