? Success

User tests: Successful: Unsuccessful:

avatar andrepereiradasilva
andrepereiradasilva
6 Apr 2016

Summary of Changes

This PR improves recaptcha render by normalizing the class and id attributes.

Testing Instructions

  • Use latest staging.

  • Enable recaptcha plugin and add your recaptcha sitekeys.

  • Set as default recaptcha in global configiguration.

  • Go to protostar index.php file and add this code inside the html body.

<?php
use Joomla\Registry\Registry;
$params = new Registry(JPluginHelper::getPlugin('captcha', 'recaptcha')->params);

JPluginHelper::importPlugin('captcha', 'recaptcha');
$dispatcher = JEventDispatcher::getInstance();

// Test recaptcha 1.0 rendering
if ($params->get('version') === '1.0' || $params->get('version') === '2.0')
{
    echo '<h4>ReCaptcha 1.0</h4>' . PHP_EOL;
    $initResult = $dispatcher->trigger('onInit');
    if ($initResult[0])
    {
        echo 'Test 1.1<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, 'dynamic_recaptcha_1', ''))) . PHP_EOL;
    }
    $initResult = $dispatcher->trigger('onInit', 'dynamic_recaptcha_2');
    if ($initResult[0])
    {
        echo 'Test 1.2<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, 'dynamic_recaptcha_2', 'extra-class'))) . PHP_EOL;
    }
    $initResult = $dispatcher->trigger('onInit', 'dynamic_recaptcha_3');
    if ($initResult[0])
    {
        echo 'Test 1.3<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, 'dynamic_recaptcha_3', 'class="extra-class"'))) . PHP_EOL;
    }
}

// Test recaptcha 2.0 rendering
if ($params->get('version') === '2.0')
{
    echo '<h4>ReCaptcha 2.0</h4>' . PHP_EOL;
    $initResult = $dispatcher->trigger('onInit');
    if ($initResult[0])
    {
        echo 'Test 2.1<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, '', 'extra-class'))) . PHP_EOL;
        echo 'Test 2.2<br/>' . implode('', $dispatcher->trigger('onDisplay')) . PHP_EOL;
        echo 'Test 2.3<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, '', 'extra-class'))) . PHP_EOL;
        echo 'Test 2.4<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, '', 'g-recaptcha'))) . PHP_EOL;
        echo 'Test 2.5<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, '', 'class=""'))) . PHP_EOL;
        echo 'Test 2.6<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, '', 'class="extra-class"'))) . PHP_EOL;
        echo 'Test 2.7<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, '', 'class="g-recaptcha"'))) . PHP_EOL;
        echo 'Test 2.8<br/>' . implode('', $dispatcher->trigger('onDisplay', array(null, 'my-custom-id', 'class="g-recaptcha extra-class"'))) . PHP_EOL;
    }
}
?>
  • Without patch:

    • captcha 1.0: load the frontpage, you'll notice invalid html code created and test 1.3 is rendered

    • captcha 2.0: load the frontpage, you'll notice invalid html code created and only tests 1.3, 2.5, 2.6 ,2.7 and 2.8 are rendered

  • With patch

    • captcha 1.0: load the frontpage, you'll notice all html code is valid and still only test 1.3 is rendered
    • captcha 2.0, load the frontpage, you'll notice all html code is valid and all recaptchas are rendered.
  • Go also to a contact form page or a forgot password page and check the recaptcha is rendered correctly.

Observations

Recapcha 1.0 will only be rendered if you add the correct sitekeys.

@810 can you check this one?

avatar andrepereiradasilva andrepereiradasilva - open - 6 Apr 2016
avatar andrepereiradasilva andrepereiradasilva - change - 6 Apr 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 6 Apr 2016
Labels Added: ?
avatar brianteeman brianteeman - change - 6 Apr 2016
Category Plugins
1c83f7c 6 Apr 2016 avatar andrepereiradasilva cs
avatar 810
810 - comment - 6 Apr 2016

still working for me

avatar andrepereiradasilva
andrepereiradasilva - comment - 6 Apr 2016

Additional info.

With this, to load one recaptcha through Joomla API (working in 1.0 and 2.0):

JPluginHelper::importPlugin('captcha', 'recaptcha');
$dispatcher = JEventDispatcher::getInstance();
$initResult = $dispatcher->trigger('onInit');
echo $initResult[0] ? implode('', $dispatcher->trigger('onDisplay')) : '';

Or for multiple recaptchas in the same page (working in 1.0 and 2.0)

JPluginHelper::importPlugin('captcha', 'recaptcha');
$dispatcher = JEventDispatcher::getInstance();
foreach (array('recaptcha_id1', 'recaptcha_id2') as $recaptchaId)
{
    $initResult = $dispatcher->trigger('onInit', array($recaptchaId));
    echo $initResult[0] ? implode('', $dispatcher->trigger('onDisplay', array(null, $recaptchaId))) : '';
}
avatar designbengel
designbengel - comment - 15 Apr 2016

Without the patch, and selecting 1.0:
Just 1.1 is rendered as ReCaptcha Version 1.0

With the patch, selecting 1.0:

still just the 1.1 is rendered as ReCaptcha Version 1.0

Without the patch, and selecting 2.0:
1.3 is rendered as NoCaptcha (Version 2), 2.1 - to 2.4 is not rendered, 2.5 - 2.8 is rendered as NoCaptcha Field (Version 2)

With the patch, selecting 2.0:
Every example is rendered as NoCaptcha Field (Version 2)


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

avatar andrepereiradasilva
andrepereiradasilva - comment - 16 Apr 2016

@designbengel actually you're test is a success, the results in my instructions were wrong.

I updated the code and the results, please mark as success.

Note: in repcaptcha 1.0 only the last 1.0 is rendered. You can check that by removing test 1.3 from the code.

avatar piotr-cz
piotr-cz - comment - 16 May 2016

I have to confirm that CAPTCHA 2.0 doesn't show up when class option is '', due to use of str_replace here which doesn't add the g-recaptcha class:

var_dump(str_replace('class="', 'class="g-recaptcha ', ''));
string(0) ""
avatar andrepereiradasilva
andrepereiradasilva - comment - 5 Sep 2016

closing as no intent to pursue this anymore

avatar andrepereiradasilva andrepereiradasilva - change - 5 Sep 2016
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2016-09-05 22:07:21
Closed_By andrepereiradasilva
avatar andrepereiradasilva andrepereiradasilva - close - 5 Sep 2016
avatar joomla-cms-bot joomla-cms-bot - change - 5 Sep 2016
Category Plugins Plugins Front End

Add a Comment

Login with GitHub to post a comment