How to use Joomla recaptcha plugin with my custom module?
Asked Answered
F

3

24

I have created a custom module for my contactus form. Now I want to use Joomla recaptcha plugin with this module.

Any idea how to get this done?

Furl answered 11/10, 2012 at 12:53 Comment(0)
B
46

In order to use joomla default recaptcha plugin follow these steps-

1)Get recaptcha keys from http://www.google.com/recaptcha

2)Set these keys to recaptcha plugin and activate it if it's not.

3)Put below code where you want to show recaptcha

//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>

4)Put this code where you validating/processing 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');
}

//For Joomla 3.x

$post = JFactory::getApplication()->input->post;
$dispatcher = JEventDispatcher::getInstance();
Bail answered 12/10, 2012 at 14:1 Comment(4)
I don't understand where to put the code in step 4. If I'm using formmail.php, would that be the place to put it? I'm confused because Google's instructions say to put this in a file they provide called verify.php.Rondo
Put this code either in model or controller.It depends why are you using form.If you dont save data but email form data so before sending this data verify that code is correct.Basically this will check whether entered code is correct.Bail
The above code stopped working in Joomla 3.5, because the ReCaptcha plugin code changed. See more details here: joomla.stackexchange.com/questions/16078/…Granicus
@Bail Might I ask you to have a look at this: joomla.stackexchange.com/q/23614/12352 ?Tumbler
O
2

Following up on Irfan's code, additionally I had to do the following for the captcha to show up:

Add the following to the template code.

JHtml::_('behavior.keepalive');

Apparently it includes the mootools library.

It seems that an event domready is added, but the event only fires when mootools library is used. So just check your html source and see if mootools is being used. I might be completely wrong but hope my solution helps someone.

Opportunist answered 8/8, 2013 at 17:19 Comment(0)
E
0

Got this from: http://jw-extension.net/joomla-how-to/138-an-easy-way-insert-captcha-in-any-module-or-component-of-joomla.html

  1. Download it

  2. login to http://www.google.com/recaptcha to get reCAPTCHA Public Key and reCAPTCHA Private Key

  3. Install , enable and enter public and private key

  4. In HTMLmodule insert {captcha} where you need to display captcha

  5. In general please insert

    global $mainframe;
    $mainframe->triggerEvent('onCaptchaDisplay');
    

to display captcha.

  1. If Auto-verify with reCAPTCHA option is enabled, the plugin will check if captcha verification data exists then automatically connect to reCAPTCHA and ask for confirmation. This method requires a little more system resource on every page load but really useful if you have many pages need captcha verification. If you don't want to enable captcha verification globally but for just few pages then you might want to disable Auto-verify with reCAPTCHA option. To verify user response, insert the following PHP code to the controller file of individual Joomla! extension where captcha verification needed:

    global $mainframe;
    $mainframe->triggerEvent('onCaptchaConfirm');
    
Empathize answered 11/10, 2012 at 16:5 Comment(2)
thanks for your response but I don't want to use any external plugin.Furl
First link obsolete (now: web.archive.org/web/20120919102733/http://jw-extension.net/…)Beauvais

© 2022 - 2024 — McMap. All rights reserved.