Description
The gform_email_field_rejectable_values allows developers to define specific email addresses or partial email patterns that should be rejected by Email type fields during form validation.
Usage
The following would apply to all forms.
add_filter( 'gform_email_field_rejectable_values', 'your_function_name', 10, 3 );
To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_email_field_rejectable_values_FORMID)
add_filter( 'gform_email_field_rejectable_values_123', 'your_function_name', 10, 3 );
Parameters
| Parameter | Type | Description |
|---|---|---|
| $rejectable_values | array | An array of values or partial values to be rejected. |
| string | The submitted email value being validated. | |
| $field | GF_Field_Email | The email field object being validated. |
Examples
Reject any email addresses containing the word ‘testing‘
add_filter( 'gform_email_field_rejectable_values', function ( $values ) {
$values[] = 'testing';
return $values;
} );
Reject specific domains
add_filter( 'gform_email_field_rejectable_values', function ( $values ) {
$values[] = '@gmail.com';
$values[] = '@mailinator';
return $values;
} );
Reject specific addresses
add_filter( 'gform_email_field_rejectable_values', function ( $values ) {
$values[] = '[email protected]';
return $values;
} );
Reject disposable domains
The following example uses a publicly maintained list of disposable email domains to reject email addresses using those domains.
add_filter( 'gform_email_field_rejectable_values', function ( $values ) {
$key = 'gform_email_field_rejectable_values-disposable-email-domains';
$domains = GFCache::get( $key );
if ( empty( $domains ) ) {
// https://github.com/disposable/disposable-email-domains
$result = wp_remote_get( 'https://disposable.github.io/disposable-email-domains/domains.json' );
if ( is_wp_error( $result ) ) {
return $values;
}
$domains = json_decode( wp_remote_retrieve_body( $result ), true );
if ( empty( $domains ) || ! is_array( $domains ) ) {
return $values;
}
GFCache::set( $key, $domains, true, DAY_IN_SECONDS );
}
return array_merge( $values, $domains );
} );
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
Gravity Forms 2.9.15
Source Code
This filter is located in includes/fields/class-gf-field-email.php