您好,我想在香菜表单验证后出现Recaptcha,但先进行Recaptcha验证,然后再次出现表单验证,再出现Recaptcha
任何帮助将不胜感激。
(?:\/\*)((.|[\r\n])*?)(?:\*\/)
答案 0 :(得分:0)
只需将其添加到表单中即可。
data-parsley-excluded =“ input [name = g-recaptcha-response],input [id = recaptcha-token]”
答案 1 :(得分:0)
这是我在cgi脚本实现中解决此问题的方法:
<form id="form" data-parsley-validate="" method=POST ACTION="">
<!--g-recaptcha-->
<div class="g-recaptcha" data-sitekey="YOUR-SITE-KEY" data-callback="recaptchaCallback"></div>
<!-- g-captcha/parsely error notice -->
<input id="myField" data-parsley-errors-container="#errorContainer" data-parsley-required="true" data-parsley-error-message="Captcha required" value="" type="text" style="display:none;"><span id='errorContainer'></span>
<!--submit-->
<input type="submit" name="submit" value="SUBSCRIBE">
</form>
<script src='https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit'></script>
<script>
var RC2KEY = 'YOUR-SITE-KEY',
doSubmit = false;
function recaptchaCallback() {
document.getElementById('myField').value = 'nonEmpty';
}
function reCaptchaVerify(response) {
if (response === document.querySelector('.g-recaptcha-response').value) {
doSubmit = true;
}
}
function reCaptchaExpired () {
/* do something when it expires */
}
function reCaptchaCallback () {
/* this must be in the global scope for google to get access */
grecaptcha.render('id', {
'sitekey': RC2KEY,
'callback': reCaptchaVerify,
'expired-callback': reCaptchaExpired
});
}
document.forms['form-name'].addEventListener('submit',function(e){
if (doSubmit) {
/* submit form or do something else */
}
})
</script>