anhskohbo / no-captcha

No CAPTCHA reCAPTCHA For Laravel.
https://packagist.org/packages/anhskohbo/no-captcha
MIT License
1.76k stars 235 forks source link

Multiple recaptcha on same page #76

Open theromie opened 7 years ago

theromie commented 7 years ago

Multiple recaptcha on same page is not showing. How can i do this?

loburets commented 6 years ago

Just youse this for each captcha at the page if you need dynamic including:

    <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
            async defer>
    </script>

    <div class="g-recaptcha"></div>

    <script>
        var onloadCallback = function() {
            //remove old
            $('.g-recaptcha').html('');

            $('.g-recaptcha').each(function (i, captcha) {
                grecaptcha.render(captcha, {
                    'sitekey' : 'your key'
                });
            });
        };
    </script>

But it is slow. You can also define all recaptchas at page initially: https://developers.google.com/recaptcha/docs/display

dosarkz commented 6 years ago

Check my version, work with Multiple recaptcha. https://github.com/dosarkz/no-captcha

ozanhazer commented 6 years ago

This does the trick for me, no jquery dependency, ie9+:

  {!! NoCaptcha::renderJs('en', true, 'recaptchaCallback') !!}

  <script>
    function recaptchaCallback() {
      document.querySelectorAll('.g-recaptcha').forEach(function (el) {
        grecaptcha.render(el);
      });
    }
  </script>