Recaptcha3 plugin

Shows and validates a Google reCAPTCHA v3

Tip

Use the Recaptcha plugin if you are still using Google reCAPTCHA v2

Usage

To use it, you need to register a site and secret keys at https://www.google.com/recaptcha/admin.

The following piece of code is the starting point to use the Recaptcha3 plugin:

The sample code above assumes that the FormValidation files are placed inside the vendors directory. You might need to change the path depending on where you place them on the server.

Options

* presents a required parameter

Option Type Description
action * String The page action
backendVerificationUrl * String The URL of your back-end that verifies the captcha via reCAPTCHA API
element * String The ID of element showing the captcha
language String The language code defined by reCAPTCHA
message * String The invalid message that will be shown in case the captcha is not valid
siteKey * String The site key provided by Google

Basic example

For testing purpose, the back-end verification always indicates that the captcha is valid.

Back-end verification

The plugin also requires verification on the server side. You need to point the backendVerificationUrl option to your back-end URL:

When click the Submit button, the plugin will send an Ajax request with the value for ___g-recaptcha-token___ parameter which is generated by reCAPTCHA. With the value of captcha token and the reCAPTCHA secret key, you can connect to reCAPTCGA verification URL to verify the captcha.

In order to inform user in case the captcha is valid or invalid, the back-end has to return a JSON encoded version of

The following code demonstrates how to do it in PHP, but you can do it with your favorite language.

Changelog

  • v1.5.0: First release. It means that the Recaptcha3 plugin requires FormValidation v1.5.0 or newer.