• Resolved abhigeorge

    (@abhigeorge)


    These functions are not working now.

    /*
    * Blacklist email domains from your WPForms.
    *
    *
    * @param int $field_id Field ID.
    * @param array $field_submit Unsanitized field value submitted for the field.
    * @param array $form_data Form data and settings.
    */

    function wpf_dev_blacklist_domains( $field_id, $field_submit, $form_data ) {
    $domain = substr( strrchr( $field_submit, “@” ), 1 );
    $blacklist = array( ‘gmail.com’, ‘yahoo.com’, ‘hotmail.com’ );

    if( in_array( $domain, $blacklist ) ) {
    wpforms()->process->errors[ $form_data[‘id’] ][ $field_id ] = esc_html__( ‘Email domain not accepted!’, ‘wpforms’ );
    return;
    }
    }

    add_action(‘wpforms_process_validate_email’, ‘wpf_dev_blacklist_domains’, 10, 3 );

    • This topic was modified 3 years, 4 months ago by abhigeorge.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Kenneth Macharia

    (@kmacharia)

    Hey @abhigeorge,

    Thanks for reaching out and sorry for the trouble.

    We’ve tested your code with a few modifications and it seems to work as expected on our end on the latest version 1.7.1.1. Would you mind testing the below code:

    /**
     * Blacklist email domains from your WPForms.
     *
     * @param int    $field_id     Field ID.
     * @param string $field_submit Unsanitized field value submitted for the field.
     * @param array  $form_data    Form data and settings.
     */
    function wpf_dev_blacklist_domains( $field_id, $field_submit, $form_data ) {
    
    	$domain    = substr( strrchr( $field_submit, '@' ), 1 );
    	$blacklist = [ 'gmail.com', 'yahoo.com', 'hotmail.com' ];
    
    	if ( in_array( $domain, $blacklist, true ) ) {
    		wpforms()->get( 'process' )->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'Email domain not accepted!', 'wpforms' );
    	}
    }
    add_action( 'wpforms_process_validate_email', 'wpf_dev_blacklist_domains', 10, 3 );

    It looks like this code is borrowing a lot from the default allow list/denylist feature in the plugin. In case it helps to know, I can suggest checking out this tutorial for more details.

    I hope this helps. ??

    Hi @abhigeorge,

    We haven’t heard back from you in about a week, so I’m going to go ahead and close this thread for now. But if you’d like us to assist further, please feel welcome to continue the conversation.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Blacklist email domains from your WPForms not working now’ is closed to new replies.