有谁知道如何使“ Google ReCAPTCHA(v2)”成为“必填项” form?
form
我的意思是直到填写Recaptcha才提交表单?
我在表单中使用ParsleyJs,但没有找到使其与divs 一起使用的方法。
div
您必须使用reCaptcha验证响应回调。像这样:<script src='https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit'></script>
<script src='https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit'></script>
var RC2KEY = 'sitekey', doSubmit = false; 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 */ } })