Require a Work Email in WPForms
Asks for a company email address instead of Gmail, Yahoo or other free webmail in WPForms email fields, so B2B forms collect qualified leads.
Opens WPIDE on
Code
$wpide_wpf_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' );
$wpide_wpf_business_forms = array(); // Form IDs; empty = all forms.
add_action( 'wpforms_process_validate_email', function ( $field_id, $field_submit, $form_data ) use ( $wpide_wpf_free_providers, $wpide_wpf_business_forms ) {
if ( $wpide_wpf_business_forms && ! in_array( (int) $form_data['id'], array_map( 'intval', $wpide_wpf_business_forms ), true ) ) {
return;
}
$email = strtolower( trim( is_array( $field_submit ) ? (string) reset( $field_submit ) : (string) $field_submit ) );
$domain = (string) substr( strrchr( $email, '@' ), 1 );
if ( $domain && in_array( $domain, $wpide_wpf_free_providers, true ) ) {
$process = method_exists( wpforms(), 'obj' ) ? wpforms()->obj( 'process' ) : wpforms()->process;
$process->errors[ $form_data['id'] ][ $field_id ] = 'Please use your work email address.';
}
}, 10, 3 );
Notes
Limit it to specific forms with the list of form IDs at the top; empty checks every form.
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.