jquery验证插件在远程时停止

时间:2014-02-07 17:22:05

标签: jquery validation plugins

接下来,我对我的一个项目有一个小问题。

我正在使用此表单上的jquery验证插件:

  

                                                 

                  <input type="text" name = "lname" placeholder="Last Name" id="lname" required/>
                  <label for="lname" generated="true" class="error"></label>

                  <input type="text" name = "email" placeholder="E-mail" id="email" class="email" required/>
                  <label for="email" generated="true" class="error"></label>

                  <input type="text" name = "username" placeholder="Username" id="username" required/>
                  <label for="username" generated="true" class="error"></label>

                  <input type="password" name = "password" placeholder="Password" id="password" required/>
                  <label for="password" generated="true" class="error"></label>

                  <input type="password" name = "cpassword" placeholder="Confirm Password" id="confirm_password" required/>
                  <label for="cpassword" generated="true" class="error"></label>

                  <input class="button" type="submit" name="regbutton" id="regbutton" value="Register" />
              </form>

以下是规则:

  

$(document).ready(function(){

     

$( '#登记')。验证({

  rules: {
          fname:{
              minlength: 3,
          },
          lname: {
              minlength: 3,
          },
          email: {
              email: true,
              remote: { url:"../php/checkemail.php", async:false >}
          },
          username: {
              minlength: 4,
              maxlength: 16,
              remote: { url:"../php/checkusername.php", async:false }
          },
          password: {
              minlength: 8,
              maxlength: 16,
          },
          cpassword: {
              equalTo: "#password",
          },
  },
      messages: {
          fname: {
              minlength: "Your name must be at least 3 characters long.",
          },
          lname: {
              minlength: "Your name must be at least 3 characters long.",
          },
          email: {
              email: "Please enter a valid e-mail address.",
              remote: "This email is already registered.",
          },
          username: {
              minlength: "Your username must be at least 4 characters long but less than 16",
              maxlength: "Your username must be at least 4 characters long but less than 16",
              remote: "This username is already registered.",
          },
          password: {
              minlength: "Your password must be at least 8 characters long but less than 16",
              maxlength: "Your password must be at least 8 characters long but less than 16",
          },
          cpassword: {
              equalTo: "The passwords do not match.",
          },
      },

  submitHandler: function(form) { 
      $('#registration').submit();
      return false;
  },
     

});   });

也是checkemail.php(checkusername.php是相同的,但显然用用户名代替电子邮件):

  

include('dbcon.php');    if(isset($ _ POST ['email']))

{
    $email = mysql_real_escape_string($_POST['email']);

    if (!empty($email)) 

{
        $email_query = mysql_query("SELECT *
                                       FROM users
                                       WHERE email = '$email'");
         if($email_query)

         {
           echo "true";
           exit;
         }
        else
        {
          echo "false";
          exit;
        }
} 
     

}

我尝试过我发现的每一种组合。简单的遥控器:“url”,具有类型和数据的那个:{function ....}等等。没有任何接缝可以工作......对于检查PHP文件是相同的,每当我在我的验证中放置远程线路单击“提交”时表单停止工作的代码。如果我删除遥控线,一切都很完美。有谁知道问题是什么?我真的没有想法,也没有地方可以找一个。

2 个答案:

答案 0 :(得分:0)

所以,

我将我的php文件更改为此,因为我认为这是我的整个验证停止的地方:

  

如果(isset($ _ POST [ '电子邮件']))

     

{

     

$ email = mysqli_real_escape_string(strtolower($ _ POST ['email']));

     

$ check = mysqli_query(“SELECT * FROM users WHERE LOWER email ='$ email'”);

     

如果(mysqli_stmt_num_rows($检查))

     

{

  echo "false";
     

}否则{

  echo "true";
     

}

     

}

但仍然没有...我没有收到任何消息,我的表格没有提交,除非我删除“remote:”url“”部分...比一切都运行得好......

答案 1 :(得分:0)

我得到了那部分工作,问题被缝合成相对网址,它无法找到php文件,所以代替../我现在使用./并且它可以工作直到那里,但在控制台它给了我200好,它给我发送“真实”,无论电子邮件和用户是否可用,它没有给我任何形式的消息......有没有人知道如何解决这个问题?

另外,如果我输入数据:{x:function ....}并输入它会跳过整个验证,让我提交一个空表格。