gform_abort_submission_with_confirmation

Description

The gform_abort_submission_with_confirmation filter determines if submissions are aborted.

When a submission is aborted:

  • The entry isn’t saved.
  • Add-on feeds won’t be processed.
  • Notifications won’t be sent.
  • The default “Thanks for contacting us! We will get in touch with you shortly.” message will be displayed instead of the forms configured confirmation. The gform_confirmation filter can be used to change the message.

By default, submissions are only aborted when identified as spam by the built-in anti-spam honeypot.

Usage

The filter which runs for all forms would be used like so:

add_filter( 'gform_abort_submission_with_confirmation', 'your_function_name', 10, 2 );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_abort_submission_with_confirmation_FORMID)

add_filter( 'gform_abort_submission_with_confirmation_6', 'your_function_name', 10, 2 );

Parameters

  • $do_abort boolean
    Indicates if the submission should abort without saving the entry. Default is false. Will be true if the anti-spam honeypot is enabled and the honeypot identified the submission as spam.
  • $form Form Object
    The form currently being processed.

Examples

Check a field value

This example shows how you can use a field value to determine if the submission should be aborted.

add_filter( 'gform_abort_submission_with_confirmation', function( $do_abort ) {
	// If submission is already marked to be aborted early, don't change it.
	if ( $do_abort ) {
		return true;
	}

	// Abort if input 1 contains 'i am a spam'.
	$is_spam = strpos( rgpost( 'input_1' ), 'i am a spam' ) !== false;

	return $is_spam;
} );

Run anti-spam checks before entry save

This example shows how you can run anti-spam checks, such as Akismet, before the entry has been saved. This will also trigger the gform_entry_is_spam filter.

GFCommon::is_spam_entry() will cache the result so it won’t run the checks again after the entry has been saved if it was found not be spam.

add_filter( 'gform_abort_submission_with_confirmation', 'abort_gf_submission_if_spam', 10, 2 );
function abort_gf_submission_if_spam( $do_abort, $form ) {
	// If submission is already marked to be aborted early, don't change it.
	if ( $do_abort ) {
		return true;
	}

	// Create an entry like array of submitted values without saving them. 
	$entry = GFFormsModel::get_current_lead();

	// Abort if spam.
	return GFCommon::is_spam_entry( $entry, $form );
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Since

This filter was added in Gravity Forms v2.7

Source Code

This filter is located in GFFormDisplay::process_form() in form_display.php.