0

after many hours of trying and searching to solve an issue with captcha issue and several faild attempts to fix the problem I decide to ask for your help, I have a web site on Joomla 2.5 I have a custom register form for new users and I want to add a captcha mechanism, where here what I made (i found it here in stackoverflow but i have some qusetions). So far I made the followings:

1)I enabled the capcha-recaptcha plugin and I enter private key and site key from google captcha

2)I set captcha-Recaptcha to Default captcha at global configuration

3)In my file template\mytemplate\html\mod_login\default.php

I enter the following code which I found here in stackoverflow

//php code
JPluginHelper::importPlugin('captcha');

$dispatcher = JDispatcher::getInstance();

$dispatcher->trigger('onInit','dynamic_recaptcha_1');

//html code inside form tag
<div id="dynamic_recaptcha_1"></div>

So far so good it appears the captcha image and entry box but when I press submit button I receive Invalid token

I suspect that it has something to do with the following part of code which it should validate/proccess the form

$post = JRequest::get('post'); 

JPluginHelper::importPlugin('captcha');

$dispatcher = JDispatcher::getInstance();

$res = $dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);
if(!$res[0]){
    die('Invalid Captcha');
}

in joomla in which file I should insert the validation code? I have tried in submit button at : template\mytemplate\html\mod_login\default.php

but nothing, I have tried also at com_users\controllers\registrattion.php still nothing any ideas where I should insert this part of code? in order to make it work?

Thnks in advance for your time!!

Regards, Jim

Community
  • 1
  • 1
  • You should definitely update your Joomla! The support for 2.5 ended a long time ago. You are prone to having your Joomla hacked! – Christoph May 08 '17 at 20:57

1 Answers1

1

EDITED ANSWER
Try this code below from https://forum.joomla.org/viewtopic.php?t=833213

$app = JFactory::getApplication();

$captchaResponse = JRequest::get('recaptcha_response_field');
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$res = $dispatcher->trigger('onCheckAnswer',$captchaResponse);
if(!$res[0])
{
  // Invalid captcha
  $app->redirect(JRoute::_('index.php?option=com_users&view=login', false));
  return false;
}

ORIGINAL ANSWER
Make sure you are using newest version of the 2.5 series. The original recaptcha plugin won't work because Google changed their API script location from recaptcha.net to google.com/recaptcha . You can open the recaptcha files to do a quick check.

YellowWebMonkey
  • 1,101
  • 7
  • 7
  • Hi thnx for answering and your time, yes I have the final version of joomla 2.5 (my version is 2.5.28), Next step is to upgrate to joomla 3.x but for its impossible for me because there are several plugins that will have issues after the upgrate – Fotths Dimitris May 08 '17 at 17:20
  • Double check the API path just to be sure. If you used some of the upgrade packs along the way, they didn't always include that plugin. I have had several client sites over the years that I had to manually overwrite. – YellowWebMonkey May 08 '17 at 21:01
  • Hi Thank you again for your respond and your help, I have checked again the API paths and everything seems to be fine, also I change the template to (joomla beez standart) and the captcha there works properly also I didn't use any external plugin for captcha but the default which is in joomla installation from the moment that captcha works in default template I believe that it has something to do with the final part of code which it should be entered in the file that it is validate / proccess the form, I entered that code to the following file : template\mytemplate\html\mod_login\default.php – Fotths Dimitris May 09 '17 at 14:44
  • Edited answer. Make sure you have $app set. – YellowWebMonkey May 09 '17 at 15:32
  • Finally I solved it as I thought was the final part of the code which was for validation / proces form I put a check solution after the submit/register button and my problem was solved, Thank tou for your time and your help my friend – Fotths Dimitris May 09 '17 at 17:31