?
avatar elioair
elioair
23 Mar 2016

Steps to reproduce the issue

In a custom extension if the captcha plugin is initialized manually like so:

JPluginHelper::importPlugin('captcha');
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onInit','my_captcha_div');
<div id="my_captcha_div"></div>

Expected result

To display the google reCaptcha field

Actual result

No reCaptcha shown.

Additional comments

Code used in 3.4.8:
// recaptcha.php
case '2.0':
    $theme = $this->params->get('theme2', 'light');
    $file  = 'https://www.google.com/recaptcha/api.js?hl=' . JFactory::getLanguage()->getTag() . '&amp;render=explicit';

    JHtml::_('script', $file, true, true);

    $document->addScriptDeclaration('jQuery(document).ready(function($) {$(window).load(function() {'
                    . 'grecaptcha.render("' . $id . '", {sitekey: "' . $pubkey . '", theme: "' . $theme . '"});'
                    . '});});'
                );
                break;
Code used in 3.5
// recaptcha.php
else
        {
            $file = 'https://www.google.com/recaptcha/api.js?onload=JoomlaInitReCaptcha2&render=explicit&hl=' . JFactory::getLanguage()->getTag();
            JHtml::_('script', $file);
            JHtml::_('script', 'plg_captcha_recaptcha/recaptcha.min.js', false, true);
        }

The issue lies in the recent refactoring of the onInit method of the plugin where it ignores the element id set upon init and since the plg_captcha_recaptcha/recaptcha.min.js script's JoomlaInitReCaptcha2 is not updated by the plugin params it looks for a div element like this one:

<div id="my_captcha_div" 
    class="g-recaptcha" 
    data-sitekey="xxxxxxxxxxxxxx" 
    data-theme="xxxx" 
    data-size="xxxx"></div>

After this modification it works.

The issue lies in the fact that the extensions using the plugin in this fashion will have to either add the key manually (not a good option) or make some changes to make it work. I'm posting this as a reference too.

avatar elioair elioair - open - 23 Mar 2016
avatar andrepereiradasilva
andrepereiradasilva - comment - 23 Mar 2016

i think this has already responded by @Fedik in another PR.
See #8867 (comment)

avatar brianteeman brianteeman - change - 23 Mar 2016
Category Plugins
avatar brianteeman brianteeman - change - 24 Mar 2016
Labels Added: ?
avatar brianteeman
brianteeman - comment - 6 Apr 2016

Closed as stated above


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

avatar brianteeman brianteeman - change - 6 Apr 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-04-06 19:55:09
Closed_By brianteeman
avatar brianteeman brianteeman - close - 6 Apr 2016
avatar arrowthemes
arrowthemes - comment - 13 Sep 2016

@elioair I'm trying to implement the captcha in a custom form and I'm facing the same issue where recaptcha isn't loaded. Could you help with the code to make it work in 3.6.x?

avatar elioair
elioair - comment - 27 Sep 2016

@arrowthemes Your container div should look like this:

<div id="your-div-id" 
    class="g-recaptcha"  // <---- has to have this class
    data-sitekey="xxxxxxxxxxxxxx"   // <---- has to have this
    data-theme="xxxx" 
    data-size="xxxx"></div>

or differently put

<div class="g-recaptcha" data-sitekey="ENTER_HERE_SITEKEY" data-theme="light" data-size="compact"></div>

For the plugin setup you can also see this.

If that fails I'd suggest looking in the above comment #8867 and the links referenced there and the div setup here. If nothing works, show me some code and I'd be happy to help further.

Add a Comment

Login with GitHub to post a comment