How to use Joomla Recaptcha plugin to a custom Joomla module?

  RedBox2
  August 7, 2013 11:37pm

I made a custom module for Contact Us form. Now I want to use Joomla Recaptcha plugin in to this module. Can anyone help me on how to implement Joomla Recaptcha?

 

5 Reponses

  Post Response
4

Follow these steps:

  1. Go to http://www.google.com/recaptcha and get your keys.
  2. Then in you Recaptcha plugin, set the keys and activate it.
  3. On your html code, put a placeholder where you want the Recaptcha to appear. See code below:

    //php code JPluginHelper::importPlugin('captcha');
    $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onInit','recaptcha');

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

     
  4. Put the code below on where you validate your contact 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 Code');
    }

You're welcome. :)

  Ben100 August 8, 2013 5:21pm reply (1)
0

@Ben100: Thank you!

  RedBox2 August 10, 2013 8:30pm reply
2

This is on the Joomla Documentations. I wonder if this is going to help you:

How do you use Recaptcha in Joomla?

There are five steps to setting up Recaptcha:

  1. Log in to your administrator back-end (How do I do this?)
  2. To enable Recaptcha
    • For Contact forms and the Registration form
      • Go to Global Configuration, and select the "Site" tab.
      • Choose "Captcha - Recaptcha" in your "Default Captcha" field.
      • Click Save & Close.
    • For the Registration form only
      • Go to your User Manager. You can find this under Users along the top menu or in the buttons on the main page of your Administrator panel.
      • Choose one of the following
        • "Use Default" in your "Default Captcha" field. (This is the default setting and follows the "Default Captcha" field setting in Global Configuration)
        • "None Selected" in your "Default Captcha" field. (This setting ignors the "Default Captcha" field setting in Global Configuration. Used when you want Recaptcha in Contact forms but not in the Registration form.)
        • "Captcha - Recaptcha" in your "Default Captcha" field. (Only needed if "Default Captcha" field setting in Global Configuration is set to "-None Selected-" and when you want the Recaptcha in contact form but not in the Contact forms).
      • Click Save & Close.
  3. Go to your Plug-In Manager. You can find this under Extension Manager along the top menu or in the buttons on the main page of your Administrator panel.
  4. Edit the Plug-In "Captcha - ReCaptcha"
    • Set Status to "Published"
    • Copy and paste the Public and Private keys in their appropriate fields on the right.
      • Get the Public and Private keys by signing in with your Google account (create an account if you don't have one) here: Create a reCAPTCHA key
      • Register your website domain, and Google will provide you with your ReCaptcha keys.
    • Click Save & Close
  KrishnaK1 August 8, 2013 12:52pm reply (1)
0

@KrishnaK1: Thank you for your answer too.

  RedBox2 August 10, 2013 8:36pm reply
0

watch out for joomla 3.2.2 update, no mootools

http://epidote1.blogspot.com.au/2014/02/joomla-322-update-breaks-custom-captcha.html

  epidote February 24, 2014 5:56am reply (0)
0

It turns out the solution presented here only works for the standard reCaptcha plugin. If you want to incorporate a plugin downloaded from the JED, you will need to modify the code a bit.

You can view the solution at http://www.simplifyyourweb.com/index.php/developers-corner/24-hands-on/260-how-to-integrate-any-captcha-plugin-into-any-custom-joomla-form

  obuisard January 24, 2015 12:49pm reply (0)