Allow Invalid Submissions

Allow form submissions to go through regardless of email validation status, while still preserving the original validation results (status, reasons, and technical details) in entry meta.

Instructions

See “Where do I put snippets?” in our documentation for installation instructions.

Code

Filename: gpev-allow-invalid-submissions.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
 * Gravity Perks // Email Validator // Allow Invalid Submissions
 * https://gravitywiz.com/documentation/gravity-forms-email-validator/
 *
 * Allow form submissions to go through regardless of email validation status, while still preserving
 * the original validation results (status, reasons, and technical details) in entry meta.
 */
$gpev_failures = array();

// Update "123" to your form ID and "4" to your Email field ID.
add_filter( 'gpev_validation_result_123_4', function( $validation_result, $value, $field, $form, $validator ) use ( &$gpev_failures ) {
	if ( ! $validation_result ) {
		return $validation_result;
	}

	if ( ! $validation_result->is_valid() ) {
		$form_id  = rgar( $form, 'id' );
		$field_id = $field->id ?? null;

		if ( $form_id && $field_id ) {
			$gpev_failures[ $form_id ][ $field_id ] = true;
		}
	}

	return $validation_result;
}, 10, 5 );

// Update "123" to your form ID and "4" to your Email field ID.
add_filter( 'gform_field_validation_123_4', function( $result, $value, $form, $field ) use ( &$gpev_failures ) {
	if ( ! gp_email_validator()->is_email_validator_field( $field ) ) {
		return $result;
	}

	$form_id  = rgar( $form, 'id' );
	$field_id = $field->id ?? null;

	if ( $form_id && $field_id && ! empty( $gpev_failures[ $form_id ][ $field_id ] ) ) {
		$result['is_valid'] = true;
		$result['message']  = '';
	}

	return $result;
}, 11, 4 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.