私はこれを何時間も熟考してきました、そして私の知恵の終わりに。同じページに2つのフォームがあり、どちらもjQuery検証を使用して送信前に有効なデータを確認しています。
編集:
以下のコードを含みます。
2つのこと:
なんらかの理由で、データを入力しているときに、最初のフォーム(登録フォーム)が検証されています。そのため、キーアップ/ブラーイベントで起動しているように見えますが、送信ボタンをクリックすると正しく起動しません。ご覧のとおり、空のデータまたは無効なデータを使用してフォームを送信できます。
右側のログインフォーム。できます!ただし、実際にフォームを送信するには、送信ボタンを2回クリックする必要があります。
拳-ここに髪がいっぱい。どうか、これを手伝ってくれる人はいますか?
編集:
必要に応じて、ここにコードを追加します。まず、登録バリデーター:
<script type="text/javascript">
$(document).ready(function() {
$.validator.addMethod("PASSWORD",function(value,element){
return this.optional(element) || /^(?=.*\d)(?=.*[a-zA-Z]).{5,}$/i.test(value);
},"Your password must be at least 5 characters long. Please include 1 or more numbers.");
$.validator.addMethod("lettersnumbers", function(value,element) {
return this.optional(element) || /^[a-zA-Z0-9]+$/i.test(value);
}, "Username can only contain letters and numbers. No spaces are allowed.");
$.validator.addMethod("BIRTH",function(value,element){
var age = 18;
switch($('#Province option:selected').val())
{
case "NB":
case "BC":
case "NL":
case "NS":
case "NY":
case "YT":
case "NU":
case "AL":
case "DE":
case "NE":
case "NV":
case "OH":
case "TN":
case "UT":
case "VA":
case "WI":
age = 19;
break;
case "MS":
age = 21;
break;
}
if (new Date().getFullYear() - year <= age)
{
return false;
}
return true;
},"In order to be eligible to Register, you must have reached the age of majority in your Province, Territory, or County of residence.");
var validator = $("#signupForm").validate({
rules: {
Captcha: {
required: true,
remote: {
url: "/js/validate_captcha.php",
type: "post",
data: {
action: function () {
return "checkcaptcha";
},
username: function() {
var Captcha = $("#Captcha").val();
return Captcha;
}
}
}
},
Password: "required PASSWORD",
PasswordConfirm: {
required: true,
minlength: 5,
equalTo: "#Password"
},
Username: {
required: true,
lettersnumbers: true,
maxlength: 18,
remote: {
url: "/js/validate_username.php",
type: "post",
data: {
action: function () {
return "checkusername";
},
username: function() {
var Username = $("#Username").val();
return Username;
}
}
}
},
Country: "required",
FirstName: "required",
LastName: "required",
Email: {
required: true,
remote: {
url: "/js/validate_email.php",
type: "post",
data: {
action: function () {
return "checkemail";
},
username: function() {
var Email = $("#Email").val();
return Email;
}
}
},
email: true
},
EmailConfirm: {
required: true,
email: true,
equalTo: "#Email"
},
BirthDate: {
required: true,
BIRTH: true
},
Agreement: "required",
AgeCheck: "required",
},
messages: {
captcha: "CAPTCHA response is required" ,
Agreement: "You must agree by checking the box" ,
AgeCheck: "You must agree by checking the box" ,
EmailConfirm: "Email Addresses do not Match",
lettersnumbers: "Username can only contain letters and numbers. No spaces allowed.",
noSpace: "Username cannot have spaces",
PasswordConfirm: "Please re-enter the same password as above",
Username:{
remote: "This username is already taken. Try another.",
maxlength: "Username may not be longer than 18 characters."
},
Captcha:{
remote: "You have entered an incorrect CAPTCHA response."
},
Email:{
remote: "This e-mail is already taken. Try another."
},
Password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long. Please include 1 or more numbers." },
required: "Required Field" ,
},
});
});
</script>
ここで、ログインバリデーターは次のとおりです。
<script type="text/javascript">
$(document).ready(function() {
var loginvalidator = $("#form_login").validate({
rules: {
LoginUser: {
required: true,
remote: {
url: "/js/validate_login_username.php",
type: "post",
data: {
action: function () {
return "checkusername";
},
username: function() {
var Email = $("#LoginUser").val();
return Email;
}
}
}
},
LoginPassword: "required"
},
messages: {
LoginUser: {
required: "Required Field",
remote: "The username or email entered was not found. Please note, your username must contain only letters and numbers, and never any spaces. Try logging in with your email address instead." },
LoginPassword: {
required: "Required Field",
remote: "Password is incorrect. Please try again." },
},
});
});
</script>