Problems When There Are Two Forms On A Page

Permalink Browser Info Environment
When using multiple forms on a page, all with recaptcha enabled, recaptcha only renders one recaptcha box. This makes it impossible to submit forms that do not have the recaptcha box rendered.

Type: Discussion
Status: Resolved
isswd
View Replies:
arvi replied on at Permalink Reply
arvi
Hi,

Thank you for a great plugin. I would like to know also the answer to this question since I have two forms in a page e.g Contact Us and Download Brochure form.

Thanks! :)
arvi replied on at Permalink Reply
arvi
Wooohooo! I was able to make it work! :D

Under /packages/ec_recaptcha/src/Captcha/RecaptchaController.php, I replaced the showInput function with this:

function showInput()
    {
        $config = Package::getByHandle('ec_recaptcha')->getConfig();
        $rag = ResponseAssetGroup::get();
         //use Google reCaptcha's explicit rendering for multiple widgets
        $lang = $config->get('captcha.language');
        if ($lang !== 'auto') {
            $rag->addFooterAsset('<script src="https://www.google.com/recaptcha/api.js?hl=' . $lang . '&onload=onloadCallback&render=explicit"
        async defer></script>');
        } else {
            $rag->addFooterAsset('<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
        async defer></script>');
        }
       //create unique recaptcha blocks
        $randomNumber = mt_rand(10000000, 99999999);



then on the footer of my website,
<script>
        var captcha;
        var onloadCallback = function() {
        var recaptchas = document.querySelectorAll('div[id^=recaptcha-block-]');
        for (i = 0; i < recaptchas.length; i++) {
            captcha = grecaptcha.render(recaptchas[i].id, {
              'sitekey' : recaptchas[i].dataset.sitekey,
              'theme'   : recaptchas[i].dataset.theme
            });
        }
      };
    </script>


Here is a sample, click the enquire now and the download brochure
http://rainingoranges.com/academics/programmes/diploma/diploma-game...

Hope this helps others who will find themselves stuck with the same issue and also maybe in the improvement of this free plugin.

Source:https://developers.google.com/recaptcha/docs/display#explicit_render...
exchangecore replied on at Permalink Reply
exchangecore
We'll have a fix for this up later today. Thank's arvi for looking in to why it doesn't work.
exchangecore replied on at Permalink Reply
exchangecore
This is fixed with the update released yesterday.

concrete5 Environment Information

# concrete5 Version
Core Version - 5.7.4
Version Installed - 5.7.4
Database Version - 20150504000000

# concrete5 Packages
Block Designer (1.0.8), ExchangeCore reCAPTCHA (0.9.0).

Browser User-Agent String

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.