Skip to main content

reCAPTCHAImproved in 5.18+

Freeform can load reCAPTCHA and verify submissions with Google in all editions. Enterprise API verification requires 5.18+. Invisible v2 requires Legacy setup.

For existing integrations, keep Setup → Legacy and your current keys, even if Google has moved them to Cloud. See Google's migration guidance.

Setup Instructions

1

Choose Setup:

  • Google Cloud uses the Enterprise API. For a new setup, use a site key, Google Cloud project ID, and Google Cloud API key.
  • Legacy uses your existing site key and secret key, including keys managed in Google Cloud.
2

Choose the Captcha Type that matches your Google key:

  • Score-based checks a risk score on submission without a checkbox or puzzle.
  • Invisible may show a puzzle on submission. Available with Legacy only.
  • Checkbox shows a checkbox and may ask the visitor to solve a puzzle.
3

Enter your credentials. See the key instructions below if you need them.

4

Set Enabled by default and click Save.

5

In the form builder, open Integrations → Captchas → reCAPTCHA. Enable the integration, review its settings, and save the form.

6

Submit a test entry on your website.

Changing Captcha Type in Freeform does not change your Google key. Their types must match.

Setup help and settings

Get keys for Google Cloud
1

Select or create a project in the Google Cloud console and enable the reCAPTCHA Enterprise API.

2

Create a website key for Score-based or Checkbox. Add your form's domains and keep Google's domain verification enabled.

3

Create an API key in the same project. Restrict it to the reCAPTCHA Enterprise API and your server's outbound IP addresses. Do not use website referrer restrictions.

4

In Freeform, choose Setup → Google Cloud and enter the Site Key, Google Cloud Project ID, and Google Cloud API Key. Use the project ID, not its display name or number.

Keep the API key private. Freeform uses it only on the server. Credentials can use environment variables, such as $RECAPTCHA_API_KEY.

Check Google's billing information for allowances, billing requirements, and quotas before enabling Enterprise verification.

Only Score-based and Checkbox keys are supported. Universal keys, policy-based challenge keys, service-account JSON files, and OAuth credentials are not supported.

Find keys for Legacy

Choose Setup → Legacy and enter your Site Key and Secret Key. To find a secret key managed in Google Cloud:

1

Open the key's details in Google Cloud and select Integration.

2

Click Use legacy key or Integrate with a third-party service or plugin.

3

Copy the legacy secret into Freeform's Secret Key field.

Use the legacy secret, not a Google Cloud API key. See Google's legacy-secret instructions.

Legacy supports Score-based v3, Invisible v2, and Checkbox v2 through Google's siteverify API, including compatible migrated keys. Keep the secret private. Freeform uses it only on the server.

Choose score and failure settings

Score Threshold is the minimum score required to pass Score-based verification. Start with 0.5 and review your results in Google before adjusting it.

  • Lower values toward 0.0 are less strict and flag fewer submissions.
  • Higher values toward 1.0 are stricter and may also flag real visitors.

Failure Behavior determines what happens when verification fails:

  • Send to Spam Folder marks the submission as spam.
  • Display Error Message lets the visitor retry. Set the text in Error Message.

New integrations default to Send to Spam Folder for Score-based and Display Error Message for both v2 types. Existing integrations keep their saved behavior. Changing Captcha Type also preserves your choice.

Missing tokens and service errors always show an error so the visitor can retry.

Loading and advanced settings

Most sites can keep the defaults.

Only load Captcha scripts once the user interacts with the form delays loading until the visitor starts filling out or submits the form. Disable it to load scripts when the page opens. Your site's consent settings still apply.

Delayed loading still requires server-side verification. Disabling the integration for a form disables verification too.

Open Advanced settings for these options:

JavaScript setup

Keep Managed by Freeform unless your code loads reCAPTCHA and generates tokens. See Custom JavaScript and headless forms below.

reCAPTCHA domain

Use google.com, or recaptcha.net if Google is blocked for your visitors. Consent settings apply to either domain.

Allowed website domains

Leave blank to use Google's domain verification. If you disable it in Google, enter the allowed hostnames here, one per line, without https://, paths, ports, or wildcards:

example.com
www.example.com
forms.example.com

Hostnames must match exactly, apart from letter case and trailing dots. example.com does not include www.example.com. For headless sites, use the frontend hostname where reCAPTCHA runs.

Checkbox theme and size

Choose a light or dark theme. Use Compact for narrow forms.

Google action name

For Score-based keys, keep submit unless you need another action. Tokens generated by your JavaScript must use the same action. Names allow letters, numbers, underscores, and slashes.

reCAPTCHA language

Leave blank to use the current Craft site language. Headless frontends let Google choose. To set a language, enter a Google language code such as en, fr, or de.

Custom JavaScript and headless forms

Using Freeform's headless packages

Keep JavaScript setup → Managed by Freeform when using Freeform's reCAPTCHA extension. It loads reCAPTCHA and supplies a token for each submission. Use compatible core and extensions packages that support your Google setup.

Providing your own token

Choose JavaScript setup → Custom JavaScript to handle script loading and tokens yourself. Freeform adds no reCAPTCHA container or scripts, and its extension leaves token handling to your code. Server verification still runs.

For regular forms, submit a fresh token in g-recaptcha-response. For Score-based keys, use grecaptcha.execute() with Legacy or grecaptcha.enterprise.execute() with Google Cloud. The action must match Google action name. For Checkbox or Invisible, obtain the token through Google's challenge flow.

For headless JSON submissions, add this to your submission payload, replacing TOKEN with Google's token:

{
"meta": {
"captcha": {
"name": "g-recaptcha-response",
"value": "TOKEN"
}
}
}

For GraphQL, use the captcha input's name and value fields.

Tokens are single-use and expire after two minutes. Generate one when submitting and get a fresh token after a failed or expired challenge. See Google's assessment guide.

Google Cloud uses enterprise.js and grecaptcha.enterprise. Legacy uses api.js and grecaptcha. The reCAPTCHA domain also applies to Legacy server verification. Google Cloud verification always uses recaptchaenterprise.googleapis.com.

Troubleshooting
  • Invalid credentials: Check that Setup and Captcha Type match your key. For Google Cloud, enable the API and use credentials from the same project.
  • Missing reCAPTCHA or token: Check whether consent tools, content blockers, or your Content Security Policy block Google's scripts. With Custom JavaScript, your code must supply the token.
  • Unexpected domain or action: Check Allowed website domains and Google action name against the hostname and token action.
  • Quota exceeded: Review Google Cloud usage and billing. Quota errors show an error to the visitor instead of marking the submission as spam.
  • Testing while logged in: If Bypass All Spam Checks for Logged in Users is enabled in Freeform's spam settings, test while signed out.

Freeform logs failures without recording tokens, credentials, or raw Google responses. Network failures, invalid credentials, incomplete responses, and quota errors are treated as service errors.

If Legacy verification returns a fixed score because the project exceeded its free allowance without billing, Freeform detects Google's quota warning and shows an error. See Google's quota behavior.

Behavior & Overrides

Disable CAPTCHA in a template with disable: { captchas: true } in the Form query. For manual token generation, choose Custom JavaScript and follow the instructions above.

Manual PlacementNew in 5.7+

To position a visible reCAPTCHA v2 Checkbox yourself, see Captcha Placement.

Add Attributes to WrapperNew in 5.1+

Add attributes to Freeform's Captcha wrapper:

{{ form.render({
captchas: {
class: ["custom-class", "another-class"],
"data-test": true,
}
}) }}