joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.76k stars 3.64k forks source link

Recaptcha does not work when used in javascript onload event #8188

Closed andrepereiradasilva closed 8 years ago

andrepereiradasilva commented 8 years ago

Steps to reproduce the issue

The recaptcha do not work if you move the javascript execution to after the javascript onload event.

Configure recaptcha plugin with version 2.0 and put it working as default in system configuration.

Use any joomla plugin that allows you to move the javascript execution to after the page onload event. Load any page with the recaptcha form and see the recaptcha image does not load.

Potencial solution

Use HTML5 "data-*" attributes when loading recaptcha.

Instead of: <script src="https://www.google.com/recaptcha/api.js?hl=__LANG__&amp;render=explicit" type="text/javascript"> [...] <div id="jform_captcha" class=" required"> [...] jQuery(document).ready(function($) {$(window).load(function() {grecaptcha.render("jform_captcha", {sitekey: "__RECAPTCHASITEKEY__", theme: "__RECAPTCHATHEME__"});});})

Use: <script src="https://www.google.com/recaptcha/api.js?hl=__LANG__&amp;render=onload" type="text/javascript"> [...] <div id="jform_captcha" class="g-recaptcha required" data-sitekey="__RECAPTCHASITEKEY__" data-theme="__RECAPTCHATHEME__"></div>

Code in: https://github.com/joomla/joomla-cms/blob/staging/plugins/captcha/recaptcha/recaptcha.php (functions onInit and onDisplay)

See also https://developers.google.com/recaptcha/docs/display#config

System information (as much as possible)

Joomla 3.4.5

zero-24 commented 8 years ago

Cab you send you changes as pull request against the staging branch?

andrepereiradasilva commented 8 years ago

ok done it. See https://github.com/joomla/joomla-cms/pull/8191

zero-24 commented 8 years ago

Closing as we have a Pull. Thanks.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8188.