Using captcha in a custom Joomla component

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. {loadposition chitika}

<?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. {loadposition social}

Tags:,

Add a Comment

Your email address will not be published. Required fields are marked *

Enjoy best web development services at an affordable price. Looking forward to build a good relationship and serve you better...

ABOUT CODINGACE

My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.

Nohman Habib

CEO: codingace.com

Request a Quote