🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!
Guides & Tutorials October 27, 2026

How to Add a Cloudflare Turnstile Captcha to Gravity Forms to Stop Spam

GravityExtra
How to Add a Cloudflare Turnstile Captcha to Gravity Forms to Stop Spam

Spam forms are a tax on every website that invites people to get in touch. A contact form left open will collect junk within days: fake sign-ups, nonsense messages, links to places you would never visit. Worse than the clutter is the doubt it plants, because once your inbox is full of rubbish you start to miss the real message in the pile. The oldest cure is a captcha, a small check that a human can pass and a script cannot. This guide shows how to add a Cloudflare Turnstile captcha to Gravity Forms, step by step, so spam and bots are stopped before an entry is ever saved, with the Gravity Forms Turnstile Premium Add-on and without writing a line of code.

What a captcha actually does

A captcha is a gate. Before a form is accepted, the visitor proves, in some small way, that they are a person and not an automated script. The classic version is a checkbox you tick. Turnstile is the same idea made quieter: a widget that most real visitors clear with a glance, and that scripts cannot clear at all. It is a general spam and bot captcha, nothing more and nothing less, and that is exactly what a contact form, a registration, a comment box or a newsletter sign-up needs.

The important part is not the widget. It is the check behind it. Turnstile hands the visitor’s browser a token, a short-lived proof that the check was passed. That token means nothing on its own; it has to be verified. A captcha that is only drawn on the page, and never confirmed on the server, can be walked straight past by a bot that skips the page and posts to the form directly. The verification is where a captcha earns its keep.

Why verification has to happen on the server

Picture a bot. It does not open your page, look at the widget and tick a box. It reads the form once, learns which fields to send, and then posts those fields to your site over and over, thousands of times, from a script. If the only thing standing in its way is a widget drawn in the browser, there is nothing to stop it, because the bot never ran the browser.

The answer is to check the token on your own server, where the bot cannot reach. When the form arrives, your site takes the Turnstile token that came with it and asks Cloudflare, over a direct connection from server to server, whether that token is genuine. Cloudflare confirms or denies it. Only a confirmed token lets the submission through. A bot that never got a real token has nothing to send, and a bot that copied one good token cannot use it twice, because each token is good for a single check.

This is the behaviour the add-on is built around. Every protected submission is verified at the Cloudflare siteverify endpoint before Gravity Forms saves anything. A missing, wrong, expired or reused answer is blocked, and no entry is written. You can read the full mechanism and every setting in the Gravity Forms Turnstile setup guide.

Step 1: make a Turnstile widget at Cloudflare

Turnstile is a free Cloudflare product, and you do not need a paid plan to use it. Sign in to the Cloudflare dashboard, find the Turnstile section and create a widget. Give it a name you will recognise later, add the domain of your site, and choose a widget mode. Managed is the usual choice; invisible is there if you prefer no visible element. Save the widget and Cloudflare gives you two values.

The site key is public. It goes into the page and is safe for anyone to see, the same as any captcha site key. The secret key is private. It stays on your server and is used only to verify tokens. Copy both; you will paste them into the add-on in the next step. Keep the secret key to yourself, the way you would any password.

Step 2: enter your keys and test them

Install and activate the add-on after Gravity Forms, then open Forms → Settings → Turnstile. Paste the site key and the secret key. The secret key is stored encrypted, so the plain value is never left sitting in your database, and it is shown masked once it is saved.

The Turnstile settings page in Gravity Forms: license key, Cloudflare site key and secret key, a test key button, protect all forms option, fail mode, verify timeout and the default theme, size and language
The settings page: paste your two keys, then press the test button to be sure they work.

Before you leave the page, press the test key button. It asks Cloudflare whether your pair of keys is accepted and tells you straight away. A green result means verification will work. A clear error means a key is wrong or the domain in Cloudflare does not match your site. Testing here saves you from discovering a typo later, when a real visitor cannot submit and you cannot see why.

Step 3: choose how forms are protected

There are two ways to put Turnstile on a form, and you can mix them.

The fast way is Protect all forms, a single switch on the settings page. Turn it on and every form on the site gets the captcha automatically, placed before the submit button, using the default look you set. If you are facing a sudden flood of spam, this is the quickest way to close the door on every form at once.

The precise way is a Turnstile field. Open a form in the editor and drop the field where you want the captcha to appear. A field lets you protect only the forms you choose and place the widget exactly, and it can carry its own theme, size and language if that form needs something different. A form with its own field uses that field; the global switch covers the rest.

A front-end Gravity Form showing the Cloudflare Turnstile widget in managed mode with a checkmark above the submit button
A live form with the widget in place: quiet for real visitors, closed to scripts.

Step 4: pick managed or invisible

Managed mode shows a small widget and lets Cloudflare decide whether a visitor has to do anything. Most people see a brief check and a tick. If a visitor looks risky, Cloudflare may ask for a simple interaction. It is visible enough that people trust it and quiet enough that it rarely gets in the way, which is why most sites choose it.

Invisible mode shows nothing. The check runs in the background and the token is gathered when the visitor presses submit. There is no widget to see, which keeps a clean form uncluttered, and the server still verifies the token exactly as it would in managed mode. Choose invisible when you want no visible element but still want every submission checked. Either way, the gate is the same: a genuine token, verified on your server, before the entry is saved.

Step 5: set the look, the language and the fail mode

On the settings page you set the defaults for every protected form. The theme can be auto, light or dark; auto follows the visitor’s system setting, so the widget looks right on a light page and a dark one. The size can be normal, flexible or compact, to fit a wide form or a narrow sidebar. The language can follow the visitor’s browser or be fixed to one you choose. Any field can override these, so the defaults are just a good starting point.

Two more settings decide what happens when the network, not the visitor, is the problem. The fail mode is either fail closed, the safe default, which blocks a submission that cannot be verified, or fail open, which lets one through when the check could not finish in time. The verify timeout sets how long the server waits for Cloudflare before it applies the fail mode. A few seconds is plenty, because a valid, wrong, expired or reused answer is decided at once; the timeout only matters during a rare network hiccup.

Step 6: check the result on an entry

Submit the form yourself and open the entry. Each entry keeps a small Turnstile result, so you can confirm protection is live. It reads passed when the token was verified and not checked when the form was not protected or the add-on had no license. It is a quiet record, useful when you are setting a form up or checking that spam has really stopped.

The Turnstile result box on a Gravity Forms entry screen showing a passed result for the verified submission
The entry screen: a passed or not-checked result kept with every submission.

It works with AJAX, multi-page and save-and-continue

Real forms are not always simple, and the captcha keeps up. On an AJAX form, where the page does not reload on submit, the widget resets after each submission so the next attempt gets a fresh token. On a multi-page form the check is handled at the final step, so a visitor is asked once at the end rather than on every page. With save and continue, a visitor can save a draft, leave, and come back, and the check is applied when they finally submit. In each case the server verifies a genuine, unused token before the entry is saved; only the moment the token is gathered changes.

Only Cloudflare is contacted, and your secret is encrypted

A captcha that stops spam should not quietly add tracking of its own. This one does not. The single outside service it contacts is Cloudflare, and only to verify a token: it sends the token and your secret key to the Cloudflare siteverify address and reads back whether the token is valid. Nothing else is called. Your secret key is kept encrypted on your site, and verification happens on your server, so a visitor cannot fake a pass by editing the page. The final word always comes from Cloudflare through your own server.

Frequently asked questions

Is Turnstile free?

Yes. Turnstile is a free Cloudflare product. You only need a Cloudflare account to make a widget and copy its site key and secret key.

Can I protect every form without editing each one?

Yes. Turn on the Protect all forms option and the captcha is added to every form automatically. Add a field only where you want precise placement.

Will a real visitor be stopped?

Almost never in managed mode, where most people clear the check with no puzzle. If you would rather never turn anyone away during a network outage, set the fail mode to fail open.

Does the captcha stop a bot that posts straight to the form?

Yes. That is the whole point of verifying on the server. A submission without a genuine, unused token is blocked before any entry is saved.

Which Gravity Forms and PHP versions are supported?

Gravity Forms 2.9 and newer, on PHP 7.4 and newer.

Get started

A captcha only works when it is checked where a bot cannot reach. The Gravity Forms Turnstile Premium Add-on puts a Cloudflare Turnstile widget on your forms and verifies every answer on your own server before an entry is saved, with managed or invisible modes, a one-press key test, and a result kept on each entry. See the features, the price and the full setup on the add-on page.

See the Turnstile add-on

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr