After upgrading to Joomla 3.5, my site / extension / custom form captcha stopped working. It does not show up, and no errors are generated anywhere.
What happened?
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It only takes a minute to sign up.
Sign up to join this communityWell, that is not a very simple one to answer, and others have already tried to explain.
Namely:
GitHub Issue #9544
Similar post in Joomla.StackExchange.com
Joomla Forum Related Post
What actually happened is that some details of the default captcha included in Joomla changed, and custom form developers that do not use a certain method to include it in their forms, need to update their code.
First, make sure that you are using the latest version of the extension that stopped working.
If you are 100% sure about that, you would need to contact the custom form developer and let them know of the issue. Including a link to this page may help them.
If you consider yourself to be confident enough with PHP, you can try to dive into the custom form code, and follow the instructions given for developers, below, until an update is issued by the custom form developer.
The ReCaptcha plugin code changed. Specifically, the function onInit
was changed in file plugins/captcha/recaptcha/recaptcha.php
. This problem will most certainly occur to your form, if you followed the instructions from this StackOverflow answer.
Many developers followed this obviously not so good idea, instead of using the JFormField
s, including Virtuemart, HikaShop, and myself.
Surprisingly enough, the $id
option included in this function, is no longer used. Instead, the file media/plg_captcha_recaptcha/js/recaptcha.min.js
was introduced, to provide a callback function for the Google ReCaptcha script:https://www.google.com/recaptcha/api.js?onload=JoomlaInitReCaptcha2&render=explicit
For some hopefully good reason, the Joomla team hardcoded the expected field class in the recaptcha.js file to be g-recaptcha
and stopped using the field id
overall. So, as also indicated in the links provided, any field without this class
, and a data-sitekey
attribute with the ReCaptcha Public Key as its value, won't work.
Thankfully, the solution is very simple. Use the JCaptcha
class instead.
$captcha_plugin = JFactory::getConfig()->get('captcha');
if ($captcha_plugin != '0') {
$captcha = JCaptcha::getInstance($captcha_plugin);
$field_id = 'your_old_and_useless_id';
print $captcha->display($field_id, $field_id, 'g-recaptcha');
}
And, of course, a one-liner version. Yay!!
print (JFactory::getConfig()->get('captcha') != '0') ? JCaptcha::getInstance(JFactory::getConfig()->get('captcha'))->display('old_field_id', 'old_field_id', 'g-recaptcha') : '';