/ 8 min read

Gravity Forms Throws Away Submissions That Fail Turnstile

Cloudflare Turnstile is spam protection, so it is natural to assume that a Gravity Forms submission failing the Turnstile check ends up in the Spam folder. It doesn’t. The official Turnstile add-on treats a failed check as a validation error, the same as a missing required field. Nothing is saved: no entry, no Spam record, no notification.

For a bot that is fine. The problem is the real people Turnstile gets wrong.

How a real lead disappears

I found this while tracking down an enquiry that a client knew had been sent but that never arrived. A third-party form tracker had captured what the visitor typed in the browser, and their details were all valid. The server logs showed the form being posted, but Gravity Forms had no record of it anywhere, Spam included. Cloudflare’s Turnstile analytics showed why: the challenge that ran as they pressed submit was unsolved and classed as “likely bot”.

The widget was in Invisible mode, which never shows the visitor anything to click. If Turnstile isn’t sure about someone, the challenge just fails, and Gravity Forms redisplays the form with “Invalid Turnstile captcha response.” Plenty of people won’t notice the message, or won’t try again. Non-interactive mode fails the same way. Only Managed mode falls back to a checkbox, and that means a visible widget on every form, so switching modes isn’t a free fix.

That tracker was the only reason anyone knew about this enquiry. Without it, there would have been nothing to find.

Where it happens

In version 1.5.1 of the add-on, GF_Field_Turnstile::validate() in includes/class-gf-field-turnstile.php does this on a failed check:

$this->failed_validation  = true;
$this->validation_message = $this->errorMessage ? $this->errorMessage : __( 'Invalid Turnstile captcha response.', 'gravityformsturnstile' );

A field that fails validation stops the submission before an entry exists, so it can never reach the spam checks.

The add-on moves the Turnstile field to the end of the form before validating, and skips the Turnstile check altogether if another field has already failed. That way the token isn’t used up on a submission that was going to fail anyway. It also means that when the Turnstile field is the only one that failed, everything the visitor typed passed validation, which is what makes it safe to let those submissions through.

How reCAPTCHA compares

Gravity Forms’ own reCAPTCHA add-on (checked in version 2.2.3) handles each reCAPTCHA type differently:

  • v3 (score-based): a submission with a valid token is accepted. If its score is at or below the threshold (0.5 by default), a gform_entry_is_spam callback sends it to Spam with a note like “Score of 0.3 is less than or equal to the threshold of 0.5.” A missing or invalid token gets a form-level validation error, and nothing is saved.
  • v2 checkbox: a failed check is a field validation error (“The reCAPTCHA was invalid. Go back and try it again.”), the same as Turnstile. The legacy CAPTCHA field in Gravity Forms core works the same way.

With reCAPTCHA v3, “probably a bot” is a low score, and borderline submissions end up in Spam where you can review them. Turnstile’s server-side check returns only pass or fail, with no score, so the add-on has nothing to compare against a threshold. The visitor Turnstile wrongly calls a bot is handled like a broken token and discarded.

Sending Turnstile failures to Spam

This mu-plugin does what the reCAPTCHA v3 integration does. If the Turnstile field is the only one that failed, it lets the submission through and then flags the entry as spam. Any other error (an invalid email, a missing required field, an email blocklist rule) is left alone, so the visitor sees it as usual.

<?php
/**
 * Plugin Name: Gravity Forms: Turnstile failures go to Spam
 * Description: Saves submissions that fail only the Turnstile check as spam
 *              entries instead of rejecting them, so false positives can be
 *              reviewed and restored.
 */

defined( 'ABSPATH' ) || exit;

$GLOBALS['gf_turnstile_failed_forms'] = array();

/**
 * Turn a Turnstile-only validation failure into a pass and remember it.
 *
 * Priority 1000 runs after the Turnstile add-on's own gform_validation
 * callback (999), which puts the field back in its original position.
 */
add_filter( 'gform_validation', function ( $validation_result ) {
	if ( ! empty( $validation_result['is_valid'] ) ) {
		return $validation_result;
	}

	$form    = $validation_result['form'];
	$form_id = absint( rgar( $form, 'id' ) );

	// Final submissions only, not multi-page navigation.
	if ( (int) rgpost( 'gform_target_page_number_' . $form_id ) !== 0 ) {
		return $validation_result;
	}

	$turnstile_fields = array();
	foreach ( $form['fields'] as $field ) {
		if ( ! $field->failed_validation ) {
			continue;
		}
		if ( 'turnstile' !== $field->type ) {
			return $validation_result; // A real error: leave it alone.
		}
		$turnstile_fields[] = $field;
	}

	if ( empty( $turnstile_fields ) ) {
		return $validation_result;
	}

	foreach ( $turnstile_fields as $field ) {
		$field->failed_validation  = false;
		$field->validation_message = '';
	}

	$validation_result['is_valid'] = true;
	$validation_result['form']     = $form;

	$GLOBALS['gf_turnstile_failed_forms'][ $form_id ] = true;

	return $validation_result;
}, 1000 );

/**
 * Flag the remembered submission as spam, with a reason on the entry.
 */
add_filter( 'gform_entry_is_spam', function ( $is_spam, $form, $entry ) {
	$form_id = absint( rgar( $form, 'id' ) );

	if ( empty( $GLOBALS['gf_turnstile_failed_forms'][ $form_id ] ) ) {
		return $is_spam;
	}

	unset( $GLOBALS['gf_turnstile_failed_forms'][ $form_id ] );

	if ( method_exists( 'GFCommon', 'set_spam_filter' ) ) {
		GFCommon::set_spam_filter(
			$form_id,
			'Turnstile',
			'Turnstile verification failed. Real visitors can fail it, so check before deleting.'
		);
	}

	return true;
}, 5, 3 );

Save it as wp-content/mu-plugins/gf-turnstile-failures-to-spam.php. It applies to every form that has a Turnstile field.

GFCommon::set_spam_filter() (Gravity Forms 2.7+) is how the built-in honeypot and Akismet record their reasons. It means you can tell these entries apart from other spam, as each one gets a note like “This entry has been flagged as spam. Reason: Turnstile verification failed. Real visitors can fail it, so check before deleting.”

What changes for visitors and for you

  • The visitor sees a confirmation message. That is what happens with any other spam filter. Unless you set up a spam confirmation (Gravity Forms 2.10+), it is Gravity Forms’ default text, not your own message, and a form that normally redirects to a thank-you page won’t redirect. Either way, a genuine person only hears back if someone checks the Spam folder.
  • Spam entries trigger nothing. Gravity Forms skips notifications and feeds for spam, so bots don’t reach your inbox or your CRM. To recover a genuine one, mark it “Not spam” and resend the notification from the entry.
  • The Spam folder fills up with the bots Turnstile used to turn away. I’d rather go through some junk than lose a real enquiry.
  • Conversion tracking may fire. Spam entries still get a confirmation, so anything that counts a conversion when it loads will count them too. See the next section.

Keeping spam out of your conversions

Gravity Forms shows spam entries its default confirmation (“Thanks for contacting us! We will get in touch with you shortly.”) unless you have set up a spam confirmation. On an AJAX form, that fires the same gform_confirmation_loaded event as a real submission. A common Google Tag Manager setup listens for that event and sends a generate_lead to GA4, which Google Ads may import as a conversion. Once Turnstile failures are accepted as spam, bots start counting as leads, and Google Ads optimises its bidding towards them.

This applies to spam from any filter, not only Turnstile. If honeypot or Akismet spam is accepted quietly on your site, it is probably being counted already.

The fix has two parts. First, add a hidden marker to the confirmation of any spam entry. This can go in the same mu-plugin:

/**
 * Mark the confirmation of any spam entry so analytics can ignore it.
 */
add_filter( 'gform_confirmation', function ( $confirmation, $form, $entry ) {
	if ( 'spam' !== rgar( $entry, 'status' ) || ! is_string( $confirmation ) ) {
		return $confirmation;
	}

	return $confirmation . sprintf(
		'<span class="gf-spam-submission" data-form-id="%d" hidden></span>',
		absint( rgar( $form, 'id' ) )
	);
}, 100, 3 );

The visitor still sees the same message. The confirmation is the response to the form POST, so page caching doesn’t affect it. If you have set up a spam confirmation that redirects, no message is rendered and the marker isn’t added, so check for spam on the redirect target instead.

Second, check for the marker in the GTM listener. In the common setup, the listener is a Custom HTML tag that fires on all pages, and each conversion tag fires on a Custom Event trigger for gravityFormSubmission. If yours looks like the one below, add the check:

<script>
  jQuery(document).on('gform_confirmation_loaded', function (event, formId) {
    var isSpam = !!document.querySelector('.gf-spam-submission[data-form-id="' + formId + '"]');
    window.dataLayer.push({
      'event': isSpam ? 'gravityFormSpam' : 'gravityFormSubmission',
      'gfFormId': formId
    });
  });
</script>

Spam pushes gravityFormSpam, which no conversion tag listens for. Real submissions work as before. Publish the GTM change before deploying the plugin, as the check does nothing until the marker exists.

Non-AJAX forms don’t fire gform_confirmation_loaded. If yours reload the page and you count conversions some other way, look for .gf-spam-submission on the confirmation page instead.

Testing it

You don’t need to make Turnstile fail in a browser. GFAPI::submit_form() runs the full validation and spam pipeline, and a submission without a Turnstile token fails the check the same way a bot’s would. Change the form ID and the input IDs to match your own form:

// wp eval-file test.php - block mail and feeds first if this is a live site
$result = GFAPI::submit_form( 1, array(
	'input_1' => 'Test',
	'input_3' => '[email protected]',
	'input_7' => 'Test message',
) );
var_dump( $result['is_spam'] ); // true with the mu-plugin, no entry without it

Use an email address on a real domain. A Gravity Forms email check or a blocklist plugin may reject example.com, and then the submission fails on the email field and never reaches Turnstile.

Once it’s in place, check the Spam folder now and then. Until the add-on handles failures the way reCAPTCHA v3 does, that is where the occasional real enquiry will be.

Robert Went

Freelance PHP developer with 19+ years experience, specialising in technical SEO, WordPress, and Laravel.

More about Rob