User tests: Successful: Unsuccessful:
This PR improves recaptcha render by normalizing the class and id attributes.
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
Go also to a contact form page or a forgot password page and check the recaptcha is rendered correctly.
Recapcha 1.0 will only be rendered if you add the correct sitekeys.
@810 can you check this one?
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
Category | ⇒ | Plugins |
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))) : '';
}
Without the patch, and selecting 1.0:
Just 1.1 is rendered as ReCaptcha Version 1.0
With the patch, selecting 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)
@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.
closing as no intent to pursue this anymore
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-09-05 22:07:21 |
Closed_By | ⇒ | andrepereiradasilva |
Category | Plugins | ⇒ | Plugins Front End |
still working for me