我有一张启用了Recaptcha的表单。如果用户未验证Recaptcha并点击提交,则会提示他/她通过错误消息进行验证。然后他们验证,但提交按钮仍然被禁用,表单无法提交。如果在没有刷新表单的情况下验证Recapthca,我该如何删除disabled属性。
到目前为止我的代码:
$(".elq-form").validate({
submitHandler: function (form) {
var captcha = grecaptcha.render('evbox-recaptcha', {'sitekey' :
'my_key'});
var response = grecaptcha.getResponse(captcha);
//recaptcha failed validation
if (response.length === 0) {
grecaptcha.reset(captcha);
$('#recaptcha-error').show();
return false;
}
//recaptcha passed validation
else {
$('#recaptcha-error').hide();
$('#submit').attr("disabled",false);
return true;
}
}
});
<p class="field-p">
<div id="recaptcha-error" style="display: none">
<p>[[%site.text.recaptcha? &topic=`default` &namespace=`site`]]</p>
</div>
<div id="evbox-recaptcha" class="g-recaptcha" data-sitekey="my_key"></div>
<input id="submit" name="submit" type="submit" value="[[%site.button.submit? &topic=`default` &namespace=`site`]]" class="submit-button button button__primary" />
</p>
答案 0 :(得分:0)
我认为你应该检查以下内容:
var captcha = grecaptcha.render('evbox-recaptcha', {'sitekey' : 'my_key'});
var response = grecaptcha.getResponse(captcha);
//recaptcha failed validation
if (response.length === 0) {
grecaptcha.reset(captcha);
$('#recaptcha-error').show();
return false;
}
答案 1 :(得分:0)
$('#submit').attr("disabled",false);