如标题所述,我遇到的问题是我在一个页面上有两个表单。是否可以为两种形式使用单个验证码?那么html5表单验证呢?我尝试使用grecaptcha函数,但它没有用。它永远不会到达formSubmit()函数。
我有以下各种形式的div:
<div class="g-recaptcha"
data-sitekey="6LeR9zEUAAAAACWWgcVtTs6JFvE0d9c2UNheIrtn"
data-size="invisible"
data-callback="formSubmit">
</div>
阻止提交按钮默认的代码:
$('###sFormId#').submit(function(event) {
if (!grecaptcha.getResponse()) {
event.preventDefault();
grecaptcha.execute();
grecaptcha.reset();
} else {
console.log('form submitted');
}
});
提交的功能:
function formSubmit(response) {
console.log('submit function');
document.getElementById("#sFormId#").submit();
}