Google reCAPTCHA V2

reCAPTCHA V2 adds Google's "I'm not a robot" checkbox to your form. Submissions that fail it go to your form's Spam tab.

Automatic Rendering

The simplest setup: Google draws the checkbox when your page loads.

1. Add your secret key

Enter your Google reCAPTCHA secret key under reCAPTCHA Secret when you create the form. For an existing form, open it in your dashboard and click Settings.

2. Add the form attribute

Add the has-recaptcha-v2 attribute to your form tag.

<form ... has-recaptcha-v2>
    ...
</form>

3. Add the reCAPTCHA script

Add Google's reCAPTCHA script to your page's head.

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

4. Add the reCAPTCHA element

Add Google's reCAPTCHA element, with your site key, inside your form where the checkbox should appear.

<div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div>

Example

Explicit Rendering

With explicit rendering, you decide when the checkbox is drawn and can pass Google extra options. Use it when your form isn't on the page yet when reCAPTCHA loads, as can happen with frameworks such as React or Angular.

Load Google's script with these options, in place of the one in step 3:

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>

Then draw the checkbox yourself, put its widget ID in a recaptcha-v2-widget-id attribute on your form tag, and call window.kwesFormsInitialize() so KwesForms picks it up:

<script>
    var myForm = document.getElementById('myForm');
    var widgetId1;
var onloadCallback = function() { // Renders the HTML element with id 'example1' as a reCAPTCHA widget. // The id of the reCAPTCHA widget is assigned to 'widgetId1'. widgetId1 = grecaptcha.render('example1', { 'sitekey' : 'YOUR_SITE_KEY', });
myForm.setAttribute('recaptcha-v2-widget-id', widgetId1);
// Re-initialize the form so KwesForms reads the widget ID. window.kwesFormsInitialize(); }; </script>

Example

How the Check Works

Google gives your form a token when a visitor ticks the checkbox, and KwesForms asks Google whether that token is valid.

flowchart TD
    accTitle: How a reCAPTCHA V2 check is done and how it can end
    accDescr: When a visitor presses Submit without ticking the checkbox, nothing is sent and the form asks them to tick it. Otherwise the token from the checkbox is sent with the submission, and KwesForms asks Google about it with your secret key. A valid token passes, and the submission goes on to the other spam checks. A token Google rejects sends the submission to the Spam tab. If Google gives no verdict the check is skipped, and the submission goes on to the other spam checks.

    submit([Visitor presses Submit]):::start --> ticked{{Is the checkbox ticked?}}:::ask
    ticked -- No --> blocked["Nothing is sent.<br/>The form asks the<br/>visitor to tick it."]:::quiet
    ticked -- Yes --> send["The token from the checkbox<br/>is sent with the submission"]
    send --> verify["KwesForms asks Google about the token<br/>with your <b>secret key</b>"]
    verify --> verdict{{What does Google answer?}}:::ask
    verdict -- "The token<br/>is valid" --> passed["<b>Passed</b><br/>On to the other<br/>spam checks"]:::good
    verdict -- "The token<br/>is rejected" --> caught["<b>Caught</b><br/>Goes to the<br/><b>Spam</b> tab"]:::bad
    verdict -- "No verdict" --> skipped["<b>Skipped</b><br/>On to the other<br/>spam checks"]:::warn

Google rejects a token that is made up, has expired or was used before. It gives no verdict when it can't be reached or when your secret key is wrong, and the check is then skipped so that no real submission is lost. If reCAPTCHA never catches anything, check your secret key.

Once a submission is sent, the visitor sees your form's success message in every case.

Notice anything wrong in our docs? Let us know.