jQuery 无论 valid/invalid 如何,验证错误消息都会出现在 reCAPTCHA 上
jQuery validate error message appears on reCAPTCHA regardless of valid/invalid
我正在尝试将 jQuery 验证脚本与新的 ReCAPTCHA 一起使用,但 ReCAPTCHA 无法验证,即使它应该是有效的。这是我的代码的精简版:
<body>
<form id="contact" method="post" action="formmail.php">
<input type="hidden" id="recipients" name="recipients" value="krishunt@toprival.com" />
<input type="hidden" name="required" value="realname: Your name" />
<input type="hidden" name="derive_fields" value="imgverify=g-recaptcha-response" />
<p><label for="realname">Name</label><br/>
<input type="text" name="realname" id="realname" class="required"/></p>
<label>Are you a robot?</label><br/>
<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha">
<div class="g-recaptcha" data-sitekey="6LewiRAUAAAAAF9928pTj2nOoKYyDKA3WpxCoit4" data-callback="recaptchaCallback"></div>
<label class="error" for="hiddenRecaptcha" generated="true"></label>
<p style="margin-top:20px"><input type="submit" value="Submit"></p>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script>
jQuery(document).ready(function() {
function recaptchaCallback() {
jQuery('#hiddenRecaptcha').valid();
};
jQuery("#contact").validate({
ignore: ".ignore",
messages: {
realname: "Please enter your full name.",
hiddenRecaptcha: "Please confirm that you are not a robot."
},
hiddenRecaptcha: {
required: function() {
if (grecaptcha.getResponse() == '') {
return true;
} else {
return false;
}
}
}
});
});
</script>
</body>
Here 是该页面的实时版本。有人可以帮忙吗?
我认为隐藏的 Recaptcha 规则需要放在规则数组中。
例如
jQuery("#contact").validate({
ignore: ".ignore",
messages: {
realname: "Please enter your full name.",
hiddenRecaptcha: "Please confirm that you are not a robot."
},
rules: {
"hiddenRecaptcha": {
required: function() {
if (grecaptcha.getResponse() == '') {
return true;
} else {
return false;
}
}
}
}
});
我正在尝试将 jQuery 验证脚本与新的 ReCAPTCHA 一起使用,但 ReCAPTCHA 无法验证,即使它应该是有效的。这是我的代码的精简版:
<body>
<form id="contact" method="post" action="formmail.php">
<input type="hidden" id="recipients" name="recipients" value="krishunt@toprival.com" />
<input type="hidden" name="required" value="realname: Your name" />
<input type="hidden" name="derive_fields" value="imgverify=g-recaptcha-response" />
<p><label for="realname">Name</label><br/>
<input type="text" name="realname" id="realname" class="required"/></p>
<label>Are you a robot?</label><br/>
<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha">
<div class="g-recaptcha" data-sitekey="6LewiRAUAAAAAF9928pTj2nOoKYyDKA3WpxCoit4" data-callback="recaptchaCallback"></div>
<label class="error" for="hiddenRecaptcha" generated="true"></label>
<p style="margin-top:20px"><input type="submit" value="Submit"></p>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script>
jQuery(document).ready(function() {
function recaptchaCallback() {
jQuery('#hiddenRecaptcha').valid();
};
jQuery("#contact").validate({
ignore: ".ignore",
messages: {
realname: "Please enter your full name.",
hiddenRecaptcha: "Please confirm that you are not a robot."
},
hiddenRecaptcha: {
required: function() {
if (grecaptcha.getResponse() == '') {
return true;
} else {
return false;
}
}
}
});
});
</script>
</body>
Here 是该页面的实时版本。有人可以帮忙吗?
我认为隐藏的 Recaptcha 规则需要放在规则数组中。
例如
jQuery("#contact").validate({
ignore: ".ignore",
messages: {
realname: "Please enter your full name.",
hiddenRecaptcha: "Please confirm that you are not a robot."
},
rules: {
"hiddenRecaptcha": {
required: function() {
if (grecaptcha.getResponse() == '') {
return true;
} else {
return false;
}
}
}
}
});