Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset Multiple Google reCAPTCHA

I have two forms on a single page which both use Google reCAPTCHA.

Whenever i use grecaptcha.reset(); it only resets the first instance.

The following JS renders the reCAPTCHA(s)

var recaptcha1;
var recaptcha2;

var myCallBack = function() {
    //Render the recaptcha1 on the element with ID "recaptcha1"
    recaptcha1 = grecaptcha.render('recaptcha1', {
        'sitekey' : '1234', //Replace this with your Site key
        'theme' : 'light'
    });

    //Render the recaptcha2 on the element with ID "recaptcha2"
    recaptcha2 = grecaptcha.render('recaptcha2', {
        'sitekey' : '1234', //Replace this with your Site key
        'theme' : 'light'
    });
};

How can i reset all instances or target a specific instance.

like image 772
Ryan Errington Avatar asked Jul 10 '15 15:07

Ryan Errington


People also ask

How do I reset Google reCAPTCHA?

For reCaptcha v2, use: grecaptcha. reset();

How long does it take for reCAPTCHA to reset?

The recaptcha expires after 60 seconds if a user validates and then doesn't press the submit button. At which point it needs to be revalidated, so it would make sense to disable the submit button when this happens too.

Can I run reCAPTCHA v2 and v3 on the same page?

Can I run reCAPTCHA v2 and v3 on the same page? To do this, load the v3 site key as documented, and then explicitly render v2 using grecaptcha.render.


1 Answers

The answer by mbejda is almost correct but not quite.

Through trial and error, I found that you have to do this:

grecaptcha.reset(recaptcha1);
grecaptcha.reset(recaptcha2);

To be clear, you have to save the return values of grecaptcha.render(), and pass in those vars to the reset() function. Passing in the string ID of the captcha doesn't work.

like image 86
Defcronyke Avatar answered Sep 28 '22 01:09

Defcronyke