Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reCAPTCHA : Grey out Submit button until backend interaction is finished

Tags:

recaptcha

I've integrated reCAPTCHA and it is working fine, except for when the users are too quick to click the Submit button right after checking the "I'm not a robot" checkbox. It takes quite some time for reCAPTCHA to register the user action via Ajax, and if they click on Submit too quickly, the g-recaptcha-response is missing, and the validation fails.

Hence my question: how to I grey out the Submit button until g-recaptcha-response value is available?

    <form id="capform" action="/captchaverify" method="POST">
        <div class="g-recaptcha" data-sitekey="..."></div>
        <p>
        <input id="capsubmit" type="submit" value="Submit">
    </form>
like image 577
rustyx Avatar asked Nov 01 '15 14:11

rustyx


People also ask

Why does Captcha keep loading?

If the I'm not a robot reCAPTCHA constantly spins after selecting the I'm not a robot reCAPTCHA box, you may be experiencing network or browser related issues. Please try either reloading the page or accessing the same page with a different browser such as Google Chrome or Mozilla Firefox.

Can you fail a reCAPTCHA?

yes it is possible to force fail a recaptcha v2 for testing purposes. by doing this browser will send previous " g-recaptcha-response " key and this will fail your recaptcha. you can make any simple post request by any application like in linux you can use curl to make post request.

What does invalid reCAPTCHA response mean?

If you are using reCAPTCHA on your site and you see the ERROR for site owner: Invalid key type message, this means that you are using an incorrect reCaptcha key type. For example, V3 keys are not compatible with V2 reCaptcha, and V2 keys are not compatible with Invisible reCaptcha. Key types are not interchangeable.

Does reCAPTCHA expire?

The reCAPTCHA verification expires after a certain amount of time so it is best to complete the reCAPTCHA verification last on a website you are accessing. Some screen readers may have difficulties getting into forms mode, if this happens, please use your screen reader's functionality to force forms mode.


1 Answers

I ended up using the data-callback attribute as described in the documentation:

<form action="/captchaverify" method="POST">
    <div class="g-recaptcha" data-sitekey="..." data-callback="capenable" data-expired-callback="capdisable"></div>
    <p>
    <input id="capsubmit" type="submit" value="Submit">
</form>

JavaScript (mootools-based, but the general idea should be clear):

function capenable() {
    $('capsubmit').set('disabled', false);
}
function capdisable() {
    $('capsubmit').set('disabled', true);
}
window.addEvent('domready', function(){
    capdisable();
});
like image 114
rustyx Avatar answered Sep 24 '22 14:09

rustyx