How to use reCAPTCHA v3 plugin with own Joomla 3.x component or module in PHP?

Ignis.Dev image
How to use reCAPTCHA v3 plugin with own Joomla 3.x component or module in PHP? 5 min read Alina
Tech

Are you looking for information on how to generate the reCAPTCHA v3 key, as well as how to use the "CAPTCHA - Invisible reCAPTCHA" plugin ("recaptcha_invisible") in the PHP code of your own custom Joomla 3.x component or module? You are in the right place, use the guide and enjoy efficient security.

4365
17/12/2019 18:41

What is reCAPTCHA?

Probably every desktop Internet user knows reCAPTCHA, which most often appears when sending data in contact forms. Squares showing similar pictures, from among which you should choose e.g. 3 pictures showing cars or rewrite distorted letters or numbers. The task of the mechanism is to check whether the data entered into the form was type by human or a bot, this is the way to protect the site against spam.

What is reCAPTCHA v3?

The improved version of reCAPTCHA v3 no longer needs to recognize people using rewritten texts or selected images, because it automatically recognizes who's dealing with. reCAPTCHA v3 installed in own custom component or module analyzes the activity on the site and based on the actions performed by the user determines whether it is dealing with a troublesome bot or a human. Using our tips you can use reCAPTCHA v3 in your custom Joomla 3.x component or module.

The tutorial contains information on how to generate the reCAPTCHA v3 key and how to use the plugin "CAPTCHA - Invisible reCAPTCHA" ("recaptcha_invisible") in the code of your own Joomla 3.x component or module in PHP.

In this article:

  1. How to generate reCAPTCHA v3 key?
  2. Joomla 3.x reCAPTCHA v3 plugin settings
  3. How to implement PHP code in your own component or module (with code example)?

1.

Generating the reCAPTCHA v3 key

To generate the reCAPTCHA v3 key go to the website:

https://www.google.com/recaptcha/intro/v3.html

In the upper right corner click the button "Admin console".
If you do not have a registered site yet, you should do it now by selecting the reCAPTCHA v3 type or if you already have a registered site, click the "+" (create) button on the right.
We fill out the form according to the hints.

2.

Joomla 3.x reCAPTCHA v3 plugin settings

In the Joomla 3.x control panel in Plugins (Extensions -> Plugins) edit plugin called "CAPTCHA - Invisible reCAPTCHA" (element: "recaptcha_invisible").

We fill in the "Site key" and "Secret key" fields with data generated a moment ago in the Google console.

We choose the position of displaying information about reCAPTCHA v3 on the page.
The plugin must be enabled!
Optionally, you can set the default CAPTCHA in the Joomla global configuration (System -> Global configuration, Site tab, Default CAPTCHA field)

3.

Implementation of PHP code in your own component or module

In the "tmpl" folder for the selected view (place where reCAPTCHA v3 will be displayed), in the default.php file or any other template, insert the following code, which must be between the html tags of your form:

<?php
JPluginHelper::importPlugin('captcha', 'recaptcha_invisible');
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onInit', 'dynamic_recaptcha_1');
$recaptcha = $dispatcher->trigger('onDisplay', array(null, 'dynamic_recaptcha_1'));
echo $recaptcha[0];
?>

In the controller, in the function that checks the data from the form (sample code):

$app = JFactory::getApplication();
$reCaptchaResponse = $app->input->get('g-recaptcha-response', '', 'string');
try {
	JPluginHelper::importPlugin('captcha', 'recaptcha_invisible');
	$dispatcher = JEventDispatcher::getInstance();
	$recaptcha = $dispatcher->trigger('onCheckAnswer', $reCaptchaResponse);
} catch(Exception $e) {
	$recaptcha = array(null);
}
if(!empty($recaptcha[0])) {
	/*form checked for the presence of bots, keep doing your stuff*/
}
Cart
0
We use cookies to improve your experience and for marketing purposes. By continuing to use our website, you accept our use of cookies. You can manage your cookie settings in your browser.
Ignisdev Ltd 2025 TOS | Privacy policy