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 |
Wooohooo! I was able to make it work! :D
Under /packages/ec_recaptcha/src/Captcha/RecaptchaController.php, I replaced the showInput function with this:
then on the footer of my website,
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...
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);
Viewing 15 lines of 17 lines. View entire code block.
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...
We'll have a fix for this up later today. Thank's arvi for looking in to why it doesn't work.
This is fixed with the update released yesterday.
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! :)