Joomla 3.5 and Recaptcha display

7 years 9 months ago - 7 years 9 months ago #1 by chrisc
We have just noticed a small problem with the display of a Recaptcha in Joomla 3.5 (and above).

Prior to Joomla! 3.5, the following code worked well to enable us to display the reCAPTCHA in a view/layout of a custom component without using JForm and a recaptcha form field:
<?php
    JPluginHelper::importPlugin('captcha');
    $dispatcher = JDispatcher::getInstance();
    $dispatcher->trigger('onInit', 'recaptcha);
?>

<div id="recaptcha"></div>

But in Joomla 3.5, things seem to have changed somewhat, and one has to modify the code to as follows:
<?php
    JPluginHelper::importPlugin('captcha');
    $dispatcher = JDispatcher::getInstance();

    // This will place the code to load the reCAPTCHA's JavaScript file into the display <head>
    $dispatcher->trigger('onInit', 'recaptcha');

    // This will return the array of HTML code.
    $recaptcha = $dispatcher->trigger('onDisplay', array(null, 'recaptcha', 'class=""'));
?>

<?php
   // Place the following where one wishes to display the reCAPTCHA.
   // Since we only have 1 recaptcha plugin enabled we use the 0 index for the HTML.
   echo (isset($recaptcha[0])) ? $recaptcha[0] : '';
?>

For more details see onInit and onDisplay function in the file plugins/captcha/recaptcha/recaptcha.php.

There may be other ways to achieve the display but the above works in our tests. Something else that changed in Joomla 3.5 that was not identified!.

Regards

If you are using our extensions please leave a review at the JED: IP Mapping | Issue Tracker | JAudit | Password Control

Please Log in or Create an account to join the conversation.

Time to create page: 0.134 seconds
Go To Top

Joomla! Debug Console

Session

Profile Information

Memory Usage

Database Queries