- Using captcha in a custom Joomla component | Blog

Blog Section

Using captcha in a custom Joomla component

on .

Using google recaptcha into a custom joomla component is so much easy. In this short post, I will show you how you can do it in just 10 minutes.

 For using captcha, you first have to get the google recaptcha key by going here https://www.google.com/recaptcha. Now login to joomla backend, go to "plugins" from the extensions menu and find out recaptcha plugin. Now open its edit page and put the google recaptcha public and private keys in the keys parameter option as shown in the figure below.

  
  
  
  After you have entered that, click the "Save" button.
  
  Now come to your component view default.php file. Copy and paste the following code before the form submit button, or where ever you want to show your recaptcha.

 <?php

JPluginHelper::importPlugin('captcha');

$dispatcher = JDispatcher::getInstance();

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

?>

//Now, the html code will automatically be thrown in the following div.

<div id="recaptcha"></div>

Put this code in your controller file or in any other file where you are processing your form.

<?php

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

JPluginHelper::importPlugin('captcha');

$dispatcher = JDispatcher::getInstance();

$result = $dispatcher->trigger('onCheckAnswer',$input['recaptcha_response_field']);

if(!$result[0]){
    die('Invalid Captcha Code');
}

?>


And thats it. It is just a simple process and requires only a few minutes to setup.

Plz share this on

Submit to DeliciousSubmit to DiggSubmit to FacebookSubmit to Google PlusSubmit to StumbleuponSubmit to TechnoratiSubmit to TwitterSubmit to LinkedIn

Services Pricing

Services Pricing

Request a Free Quote

Email an Enquiry