Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_captcha_validation_failed

Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or third-party development.

Use the frm_captcha_validation_failed action to run your own code when a reCAPTCHA, hCaptcha, or Cloudflare Turnstile check fails. It receives the reason for the failure and the error codes from the CAPTCHA service. Use it to log failures or to alert someone when the CAPTCHA isn't set up correctly.

Requirements

  • Formidable Forms 7.0 or later.
  • The action is in Formidable Forms Lite. It works with or without Formidable Forms Pro.
  • A CAPTCHA field on the form, with keys saved in Formidable → Global Settings → Captcha/Spam.

Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.

Usage

add_action( 'frm_captcha_validation_failed', 'my_captcha_validation_failed', 10, 4 );

Parameters

  • $reason (string): A readable explanation of the failure, such as "The CAPTCHA response expired or was already used."
  • $error_codes (array): The error codes returned by the CAPTCHA service, such as 'timeout-or-duplicate'. It can be empty.
  • $form_id (int): The ID of the form being submitted.
  • $field (array|object): The CAPTCHA field.

When the action runs

The action runs in each of these cases:

  • No CAPTCHA response: The form was submitted without a CAPTCHA response, for example before the CAPTCHA loaded. $error_codes is array( 'missing-input-response' ).
  • Service can't be reached: Your site couldn't connect to the CAPTCHA service. $reason is the connection error and $error_codes is empty.
  • Response rejected: The CAPTCHA service rejected the response. This includes a reCAPTCHA v3 score below your threshold.

It runs before Formidable applies the CAPTCHA errors spam check. So it fires whether that check is set to Save as a spam entry or Reject with an error message.

When the submission is saved as a spam entry, the reason and error codes are saved with it. Learn more about spam checks.

Examples

Learn where to put the code when adding a custom PHP function to your site.

Log every failed CAPTCHA check

This example writes each failure to the PHP error log, with the form ID, the reason and the error codes. It needs logging turned on for your site, for example with WP_DEBUG_LOG.

add_action( 'frm_captcha_validation_failed', 'my_log_captcha_failures', 10, 3 );
function my_log_captcha_failures( $reason, $error_codes, $form_id ) {
	error_log(
		sprintf(
			'CAPTCHA failed on form %d: %s (%s)',
			$form_id,
			$reason,
			$error_codes ? implode( ', ', $error_codes ) : 'no codes'
		)
	);
}

Email the site admin about a CAPTCHA setup problem

Some error codes mean the CAPTCHA keys are missing or wrong. When this happens, no visitor can pass the check.

This example emails the site admin when one of these codes comes back. It sends at most 1 email per hour.

add_action( 'frm_captcha_validation_failed', 'my_alert_on_captcha_setup_error', 10, 3 );
function my_alert_on_captcha_setup_error( $reason, $error_codes, $form_id ) {
	$setup_codes = array(
		'missing-input-secret',
		'invalid-input-secret',
		'bad-request',
		'invalid-sitekey',
		'sitekey-secret-mismatch',
		'not-using-dummy-passcode',
		'not-using-dummy-secret',
		'invalid-widget-id',
		'invalid-parsed-secret',
	);

	if ( ! array_intersect( $setup_codes, $error_codes ) || get_transient( 'my_captcha_setup_alert_sent' ) ) {
		return;
	}

	wp_mail(
		get_option( 'admin_email' ),
		'CAPTCHA setup problem',
		sprintf( 'A CAPTCHA check failed on form %d: %s', $form_id, $reason )
	);

	set_transient( 'my_captcha_setup_alert_sent', 1, HOUR_IN_SECONDS );
}

Limitations

  • The action can't change the error message or stop the failure. To change the message, use the frm_captcha_error_message filter.
  • The error codes differ between CAPTCHA services. Check for every code you want to handle.
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2026 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Don't forget your purchase!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms