Upgrade to 3.5.0 or install 3.5.0. Open standard contact form with Google Recaptcha enabled.
Google Recaptcha should load/display.
Google Recaptcha does not load/display.
Joomla 3.5.0 (either upgraded from earlier version or clean install)
Neither the label nor the recaptcha load. On all sites tested, recaptcha loaded as expected until upgrade to 3.5.0.
Status | New | ⇒ | Information Required |
Category | ⇒ | Plugins |
Fix to make your custom component work again with joomla's recaptcha:
<?php else : ?>
<div class="g-recaptcha" data-sitekey=“YOUR_SITE_KEY" data-theme="light" data-size="normal"></div>
<?php endif; ?>
That fixes the problem. I learned more about the issue after I posted this message. As it turns out, unless "Captcha - ReCaptcha" is set under Global Configuration > Site > Default Captcha, even though under "Global Configuration > Contacts > Form > Allow Captcha on Contact" was set to Captcha - Recaptcha, it would not work. You had to have it set to "Captcha - ReCaptcha" under the Site tab (Global Config). The patch fixed this and it now behaves as it did before the upgrade to 3.5.0.
Thanks!
Status | Information Required | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-03-31 22:35:33 |
Closed_By | ⇒ | brianteeman |
Hi
Thanx for the fix, but in which file to paste it ?
You need to change the html with which you call joomla's recaptcha plugin. So you need to edit your form's default.php file so it will show the recaptcha irrespective of your joomla version like this:
<?php if (version_compare(JVERSION, '3.5', '<')) : ?>
<div id="dynamic_recaptcha_1"></div>
<?php else : ?>
<div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY" data-theme="light" data-size="normal"></div>
<?php endif; ?>
but you would like to instatiate it manually (and also do validation manually on the controller save task)
it is better to avoid adding the HTML / JS / etc of the captcha directly
Instead the API display() method should be used
something like this will work with (please correct any syntax or other errors ...):
FORM
$captcha_field_html = '';
// Use configured captcha plugin
if ( $c_plugin = JFactory::getApplication()->getCfg('captcha') )
{
// Try to load the configured captcha plugin, (check if disabled or uninstalled)
// Joomla will enqueue an error message if needed
$captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => 'my_component_form'));
$captcha_field_html = $captcha_obj ?
$captcha_obj->display('captcha_field_name', 'captcha_tag_id', ' captcha_outer_class ') :
'' ;
}
CONTROLLER save task
// ** Extra validation for manually added captcha
// Use configured captcha plugin
if ( $c_plugin = JFactory::getApplication()->getCfg('captcha') )
{
// Get captcha value
$c_value = $app->input->get('captcha_field_name', null, 'STRING');
// Get captch object instance
$captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => 'my_component_form'));
// Validate catcha
if (!$captcha_obj->checkAnswer($c_value))
{
// Get the captcha validation message and push it out to the user
// but default error message is not good ? maybe use custom here
$error = $captcha_obj->getError();
$app->enqueueMessage($error instanceof Exception ? $error->getMessage() : $error, 'error');
// Set POST form data into the session, so that they get reloaded
$app->setUserState($form->option.'.edit.'.$form->context.'.data', $data);
// Redirect back to the component form
$this->setRedirect( '...' );
return false;
}
}
Please can you test with 3.5.1 release candidate 2 as there were some fixes made to the recapatcha that I think have been resolved https://github.com/joomla/joomla-cms/releases/tag/3.5.1-rc2
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.