Skip to content

Instantly share code, notes, and snippets.

@ajskelton
Created April 5, 2018 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajskelton/402c3c0c1da5edbbf7e4022d982810c5 to your computer and use it in GitHub Desktop.
Save ajskelton/402c3c0c1da5edbbf7e4022d982810c5 to your computer and use it in GitHub Desktop.
Gravity Forms email blacklist
add_filter( 'gform_field_validation', 'PREFIX_gravity_forms_blacklist', 10, 4 );
/**
* Added Validation check for email vs blacklist of free email accounts.
*
* @param $result array The validation result to be filtered
* @param $value string|array The field value to be validated
* @param $form object Current Form object
* @param $field object Current Field object
*
* @return mixed
*/
function PREFIX_gravity_forms_blacklist( $result, $value, $form, $field ) {
if ( $field->get_input_type() === 'email' && $result['is_valid'] ) {
$domain = explode( '@', $value );
$blacklist = array(
'gmail.com',
'yahoo.com',
'hotmail.com'
);
if ( in_array( $domain[1], $blacklist ) ) {
$result['is_valid'] = false;
$result['message'] = 'Please use a work email.';
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment