· 8 years ago · Apr 13, 2018, 06:25 PM
1add_filter( 'gform_field_validation', 'PREFIX_gravity_forms_blacklist', 10, 4 );
2/**
3 * Added Validation check for email vs blacklist of free email accounts.
4 *
5 * @param $result array The validation result to be filtered
6 * @param $value string|array The field value to be validated
7 * @param $form object Current Form object
8 * @param $field object Current Field object
9 *
10 * @return mixed
11 */
12function PREFIX_gravity_forms_blacklist( $result, $value, $form, $field ) {
13 if ( $field->get_input_type() === 'email' && $result['is_valid'] ) {
14
15 $domain = explode( '@', $value );
16 $blacklist = array(
17 'gmail.com',
18 'yahoo.com',
19 'hotmail.com'
20 );
21
22 if ( in_array( $domain[1], $blacklist ) ) {
23 $result['is_valid'] = false;
24 $result['message'] = 'Please use a work email.';
25 }
26 }
27
28 return $result;
29}