在我的网站上添加一个Recaptcha之前,我有一个用于用户将所有用户输入发布到我的数据库中的表单。但是,如果有一个仍然为空或值为0的字段,我将禁用提交按钮。我使用jQuery来完成此操作
我已经尝试过使用val()方法捕获recaptcha valeu,但似乎无法正常工作。
这是我的jQuery,可在检查所有字段后启用提交或禁用它:
$('#identity-next').attr('disabled', true); //disable the button
function checkFilled() {
$('form').on('keyup change', function () {
if ($(name).val() != ""
&& $(birth_place).val() != 0
&& $(birth_date).val() != ""
&& $(email).val() != ""
&& $(phone_number).val() != ""
&& $(address_province).val() != 0
&& $(address_regency).val() != 0
&& $(address_district).val() != 0
&& $(specify_address).val() != 0
&& $(captcha).val() != "") // the one that's not working {
$('#identity-next').attr('disabled', false); return true;
}
else {
$('#identity-next').attr('disabled', true);
return false;
}
});
}
checkFilled() //call the function
这是我的验证码div:
<div id="captcha" name="g-recaptcha" class="g-recaptcha"
data-sitekey="########################">
</div>
{!! NoCaptcha::renderJs() !!}
<span class="text-danger">{{ $errors->first('g-recaptcha-response') }}
</span>
所以我希望我的jquery函数可以处理相同的功能,以在所有字段(包括我的Recaptcha)都不为空时启用提交按钮,我正在使用recaptcha V2 btw。在这种情况下,我的按钮将保持禁用状态,因为验证码完全不返回任何值(?)。
最诚挚的问候!