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 );
}

Integrate Zero Spam with Save and Continue

The following example shows how to check the key used by the Zero Spam Add-On when the Save & Continue submission is processed (e.g. the Save & Continue button is clicked).

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

	$saving_for_later = (bool) rgpost( 'gform_save' );

	// Don't abort when the user is not saving their progress via the save and continue button.
	if ( ! $saving_for_later ) {
		return false;
	}

	// Don't abort when there isn't a Zero Spam key saved to the database.
	$key = get_option( 'gf_zero_spam_key' );
	if ( empty( $key ) ) {
		return false;
	}

	// Don't abort when the Zero Spam check is disabled for the form.
	$should_check_key_field = ! GFCommon::is_preview();
	$should_check_key_field = gf_apply_filters( 'gf_zero_spam_check_key_field', rgar( $form, 'id' ), $should_check_key_field, $form, array() );
	if ( ! $should_check_key_field ) {
		return false;
	}

	$submitted_key = rgpost( 'gf_zero_spam_key' );
	if ( empty( $submitted_key ) ) {
		GFCommon::log_debug( 'gform_abort_submission_with_confirmation: Zero Spam key was not submitted.' );

		return true;
	}

	$do_abort = $key !== html_entity_decode( sanitize_text_field( $submitted_key ) );
	GFCommon::log_debug( 'gform_abort_submission_with_confirmation: Zero Spam key valid? ' . ( $do_abort ? 'No' : 'Yes' ) );

	return $do_abort;
}, 20, 2 );

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.