如何获取 recaptcha 值,以便它可以用于条件检查

how to get the recaptcha value so that it can be used in a condition check

在我的网站上添加验证码之前,我有一个表单用于用户 post 所有用户输入到我的数据库中。但是如果有一个字段仍然是空的,或者值为 0,我禁用了提交按钮。我使用 jQuery 来完成这个

我试过使用 val() 方法来捕获 recaptcha 值,但似乎不起作用。

这是我的 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。在这种情况下,我的按钮将保持禁用状态,因为验证码 return 根本没有价值(?)。

此致问候!

您的问题的解决方案是:

if($("#g-recaptcha-response").val()!="") {
    //show button
}