Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery身份验证密码不匹配_Jquery_Html_Forms_Authentication_Forms Authentication - Fatal编程技术网

jquery身份验证密码不匹配

jquery身份验证密码不匹配,jquery,html,forms,authentication,forms-authentication,Jquery,Html,Forms,Authentication,Forms Authentication,如果你能告诉我这段代码哪里出了问题,我将不胜感激——我是一个初学者,所以请大家放松 我有一个如下的表单和一些基本的jQuery身份验证。一切似乎都很好,接受检查密码是否匹配,这告诉我密码每次都匹配,我一辈子都搞不清楚发生了什么事 Html格式: <form name="signupform" id="signupform" action="signup.php" method="post"> <div>Email Address</div> <inp

如果你能告诉我这段代码哪里出了问题,我将不胜感激——我是一个初学者,所以请大家放松

我有一个如下的表单和一些基本的jQuery身份验证。一切似乎都很好,接受检查密码是否匹配,这告诉我密码每次都匹配,我一辈子都搞不清楚发生了什么事

Html格式:

 <form name="signupform" id="signupform" action="signup.php" method="post"> 
<div>Email Address</div>
<input id="email" name="email" type="text" maxlength="88">
<span id="emailstatus"></span>
<div>Full Name</div>
<input id="personname" name="personname" type="text" maxlength="20">
<div>Create Password</div>
<input id="password1" name="password1" type="password" maxlength="100">
<div>Confirm Password</div>
<input id="password2" name="password2" type="password" maxlength="100"> 
<div>Address Line 1</div>
<input id="address_line1" name="address_line1" type="text" maxlength="100">
<div>Address Line 2</div>
<input id="address_line2" name="address_line2" type="text" maxlength="100">
<div>City</div>
<input id="address_city" name="address_city" type="text" maxlength="100">
<div>State</div>
<input id="address_state" name="address_state" type="text" maxlength="100">
<div>Post Code/ ZIP Code</div>
<input id="address_zip" name="address_zip" type="text" maxlength="100">
<div>Country</div>
<select id="address_country" name="address_country">
  <?php include_once("template_country_list.php"); ?>
</select><br><br>

<button class="inline-block" id="signupbtn">Create Account</button>
<p id="error">There were errors on the form, please make sure all fields are fill out correctly.</p>
<p id="passmatcherror">Passwords do not match.</p>
Jquery:

$(document).ready(function(){
var pname = $("#personname");
var e = $("#email");
var p1 = $("#password1");
var p2 = $("#password2");
var country = $("#address_country");
var add1 = $("#address_line1");
var add2 = $("#address_line2");
var city = $("#address_city");
var state = $("#address_state");
var zip = $("#address_zip");
var status = $("#status");
// Place ID's of all required fields here.
required = ["personname", "email", "password1", "password2", "address_country", "address_line1", "address_line2", "address_city", "address_state", "address_zip"];
// If using an ID other than #email or #error then replace it here
email = $("#email");
errornotice = $("#error");
passmatcherror = $("#passmatcherror");
passmatcherror.hide();
// The text to show up within a field when it is incorrect
emptyerror = "";
emailerror = " Please enter a valid e-mail.";
$("#signupform").submit(function(){ 
    //Validate required fields
    for (i=0;i<required.length;i++) {
        var input = $('#'+required[i]);
        if ((input.val() == "") || (input.val() == emptyerror)) {
            input.addClass("needsfilled");
            input.val(emptyerror);
            errornotice.fadeIn(750);
        }

         else {
            input.removeClass("needsfilled");
        }
    }
    // Validate the e-mail.
    if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
        email.addClass("needsfilled");
        email.val(emailerror);
    }

    if(p1 != p2){
            passmatcherror.fadeIn(750);
            p1.addClass("needsfilled");
            p2.addClass("needsfilled");

        }


    //if any inputs on the page have the class 'needsfilled' the form will not submit
    if ($(":input").hasClass("needsfilled")) {
        return false;
    } else {
        errornotice.hide();
        return true;
    }
});

// Clears any fields in the form when the user clicks on them
$(":input").focus(function(){       
   if ($(this).hasClass("needsfilled") ) {
        $(this).val("");
        $(this).removeClass("needsfilled");
        errornotice.hide();
        passmatcherror.hide();
       }
        });
}); 

在本节中,您似乎比较了两个jquery对象,而不是它们的值:

if(p1 != p2){
    passmatcherror.fadeIn(750);
    p1.addClass("needsfilled");
    p2.addClass("needsfilled");
}
如果您将其更改为

if(p1.val() !== p2.val()){
    passmatcherror.fadeIn(750);
    p1.addClass("needsfilled");
    p2.addClass("needsfilled");
}

好极了现在可以了!非常感谢你-我不会再犯这样的错误:我会投你一票-但我只是刚刚加入,所以我不能:对不起,没问题,我们都从某个地方开始!