• Resolved bengriff64

    (@bengriff64)


    Hi,

    I have a form creating a user and it works perfectly, unless you enter the same username or email that already exists. The issue I have is that it doesn’t display an error or anything, it just says updated.

    Is there a way I can make it error if the username or email already exist?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    You can use this snippet your field.

    // unique User email
    add_filter('acf/validate_value/name=registration_email', 'registration_email_validation', 10, 4);
    function registration_email_validation($valid, $value, $field, $input){
        
        if(!$valid)
            return $valid;
        
        $exists = email_exists( $value );
        if ( $exists )
            $valid = 'E-mail already exists';
        
        return $valid;
        
    }

    You can do the same with username using
    $check = username_exists($generated_username);

    Cheers

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello @bengriff64 & @popsantiago,

    Thanks for the report. In fact @popsantiago has written exactly what I was about to answer 🙂

    You can use his snippet to validate those values. Here is documentation for the reference: https://www.advancedcustomfields.com/resources/acf-validate_value/

    Thanks for your help @popsantiago!

    Have a nice day.

    regards.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Username/Email Validation’ is closed to new replies.