amiroperator amiroperator - 4 months ago 40
HTML Question

Multiple instane of Google reCaptcha

I used google reCaptcha for my website and my login and register form are in same page and when I use reCaptcha twice, the second captcha doesn't work.

I used this code for login and register form:

<div class="g-recaptcha" data-sitekey="********"></div>


Any body can help me to solve it ?

https://www.google.com/recaptcha/

Answer

By using the following code I fixed that problem:

form:

<div id="captcha"></div>

head:

var captchaCallback = function() {
    grecaptcha.render('captcha', {
        'sitekey' : ''
    });
};

</script>

<script src="//www.google.com/recaptcha/api.js?onload=captchaCallback&render=explicit&hl=en" async defer></script>