[英]jquery validator continues even though all rules have not been met
I have basic html and want to validate the fields with jQuery validator so I have less validation on php level. 我有基本的html,想用jQuery验证程序来验证字段,所以我在php级别上的验证较少。 The form validates if all fields are empty and prevents submission to php but as soon as I complete 1 input the form sumits (even if all other fields are blank).
表单会验证所有字段是否为空,并阻止提交到php,但是一旦我完成1输入表单汇总(即使所有其他字段均为空白)。 All fields are required so I'm stumped - please help!
所有字段都是必填项,因此我很困惑-请帮助!
After some of your advice I have redone my validation on php level but it has the exact same effect. 经过您的一些建议后,我已在php级别上重做了验证,但效果完全相同。 If all the fields are empty the validation works, as soon as 1 field is filled in the form submits.
如果所有字段均为空,则在提交表单时,只要填写了1个字段,验证就会生效。
jQuery: I ran it through JSLint and it yielded no errors - unbelievable right?! jQuery:我通过JSLint运行它,但未产生任何错误-令人难以置信的对吗?
$().ready(function () {
"use strict";
$('#register').validate({
rules: {
firstname: {
required: true,
maxLength: 40
},
lastname: {
required: true,
maxLength: 40
},
email: {
required: true,
maxLength: 64,
email: true
},
password: {
required: true,
minLength: 6,
maxLength: 32
},
confirmPassword: {
required: true,
equalTo: "#password"
},
rsaid: {
required: true,
digits: true
}
},
messages: {
firstname: {
required: "Please enter your first name.",
maxLength: "Your first name cannot exceed 40 characters."
},
lastname: {
required: "Please enter your last name.",
maxLength: "Your last name cannot exceed 40 characters."
},
email: {
required: "Please enter your email address.",
maxLength: "Your email address cannot exceed 64 characters.",
email: "The email format provided is invalid."
},
password: {
required: "Please enter a password.",
minLength: "Your password must contain at least 6 characters.",
maxLength: "Your password cannot contain more than 32 characters."
},
confirmPassword: {
required: "Please confirm your password.",
equalTo: "Your passwords do not match!"
},
rsaid: {
required: "Please enter a valid RSA id number.",
//exactLength: "Your ID number must contain 13 characters!",
digits: "Your ID number must consist of numerals only!"
}
},
errorContainer: $('#errorContainer'),
errorLabelContainer: $('#errorContainer ul'),
wrapper: 'li'
});
});
html: Shouldn't be necessary but just in case :) html:应该没有必要,但以防万一:)
<div class="registrationForm">
<form id="register" action="php/insert.php" method="post">
<input type="text" id="firstname" name="firstname" placeholder="First Name" value="" class="radius mini" />
<input type="text" id="lastname" name="lastname" placeholder="Last Name" value="" class="radius mini"/>
<input type="text" id="email" name="email" placeholder="Your Email" value="" class="radius" />
<input type="password" id="password" name="password" placeholder="New Password" value="" class="radius" />
<input type="password" id="confirmPassword" name="confirmPassword" placeholder="Confirm Password" value="" class="radius" />
<input type="text" id="rsaid" name="rsaid" placeholder="RSA ID Number" value="" class="radius" />
<button class="radius title" name="signup">Sign Up for SFC</button>
</form>
</div>
PHP code: This contains code for only the first 3 fields as password validation is long and irrelevant. PHP代码:由于密码验证时间长且不相关,因此仅包含前3个字段的代码。 The code returns no errors on phpcodechekcer.com.
该代码在phpcodechekcer.com上未返回任何错误。
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["firstname"])) {
$firstnameErr = "First name is required";
} else {
$firstname = mysqli_real_escape_string($link, $_POST['firstname']);
}
if (empty($_POST["lastname"])) {
$lastnameErr = "Last name is required";
} else {
$lastname = mysqli_real_escape_string($link, $_POST['lastname']);
}
if (empty($_POST["email"])) {
$emailErr = "Email address is required";
} else {
if (!isValidEmail($_POST["email"])) {
$emailErr = "Email address is invalid";
} else {
$email = mysqli_real_escape_string($link, $_POST['email']);
}
}
}
最好在服务器端进行验证,如果您的客户端在浏览器上关闭了javascript,则所有数据都将发送到服务器,而无需任何验证
html标头上需要jquery文件链接。
Perhaps it's because you are not using fieldset enclosing? 也许是因为您没有使用字段集包围? On the other side, you may look towards plain HYML5 validation.
另一方面,您可能希望进行简单的HYML5验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.