Require a Work Email in Fluent Forms
Asks for a company email address instead of Gmail, Yahoo or other free webmail in Fluent Forms, so B2B forms bring in qualified leads.
Opens WPIDE on
Code
$wpide_ff_work_forms = array(); // Form IDs; empty = all forms.
$wpide_ff_work_field = 'email'; // Email field name.
$wpide_ff_free_providers = array( 'gmail.com', 'googlemail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 'live.com', 'aol.com', 'icloud.com', 'gmx.com', 'proton.me', 'protonmail.com', 'mail.com', 'yandex.com' );
add_filter( 'fluentform/validation_errors', function ( $errors, $data, $form ) use ( $wpide_ff_work_forms, $wpide_ff_work_field, $wpide_ff_free_providers ) {
if ( $wpide_ff_work_forms && ! in_array( (int) $form->id, array_map( 'intval', $wpide_ff_work_forms ), true ) ) {
return $errors;
}
$email = isset( $data[ $wpide_ff_work_field ] ) && is_string( $data[ $wpide_ff_work_field ] ) ? strtolower( trim( $data[ $wpide_ff_work_field ] ) ) : '';
$domain = (string) substr( strrchr( $email, '@' ), 1 );
if ( $domain && in_array( $domain, $wpide_ff_free_providers, true ) ) {
$errors[ $wpide_ff_work_field ] = array( 'Please use your work email address.' );
}
return $errors;
}, 10, 3 );
Notes
Limit it to forms in the list at the top; the field named "email" is checked unless you change it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.