• Resolved kooogi

    (@kooogi)


    Hi everyone

    Hi everyone

    It is possible to add additional validation / customize messages in password reset form and to do the same thing in register form with username (user_login) field.
    I wrote this code in php and in my opinion it should work but it doesn’t

    add_action( 'um_reset_password_form', 'my_reset_password_form', 10, 1 );
    function my_reset_password_form( $args ) {
        if ( isset( $args['username'] ) ) {
    		if ( isset( UM()->form()->errors['username'] ) ) {
    			unset( UM()->form()->errors['username'] );
    		}
    		if ( empty( $args['username'] ) ) {
    			UM()->form()->add_error( 'username', __( 'Enter username or email address', 'ultimate-member' ) );
    		} elseif ( ! email_exists( $args['username'])  || ! username_exists( $args['username']) ) {
    			UM()->form()->add_error( 'username', __( 'username or email address doesnt exists', 'ultimate-member' ) );
    		}
    	}
    }

    thanks in advance

Viewing 10 replies - 1 through 10 (of 10 total)
  • @kooogi

    Try to use this hook “um_reset_password_errors_hook” for your code snippet

    https://ultimatemember.github.io/ultimatemember/hooks/um_reset_password_errors_hook.html

    For the Registration Form use Custom Validation explained in this guide.

    https://docs.ultimatemember.com/article/94-apply-custom-validation-to-a-field

    Thread Starter kooogi

    (@kooogi)

    @missveronicatv

    Unfortunately nothing change, its looks like “um_reset_password_errors_hook” doesnt works too. And the second thing i cant set custom validation on user_login, there’s only “no validation” or “unique check”.

    @kooogi

    You can try this updated code snippet where I have changed username to username_b

    add_action( 'um_reset_password_errors_hook', 'my_reset_password_form', 10, 2 );
    function my_reset_password_form( $args, $form_data ) {
        if ( isset( $args['username_b'] ) ) {
    		if ( isset( UM()->form()->errors['username_b'] ) ) {
    			unset( UM()->form()->errors['username_b'] );
    		}
    		if ( empty( $args['username_b'] ) ) {
    			UM()->form()->add_error( 'username_b', __( 'Enter username or email address', 'ultimate-member' ) );
    		} elseif ( ! email_exists( $args['username_b'])  || ! username_exists( $args['username_b']) ) {
    			UM()->form()->add_error( 'username_b', __( 'username or email address doesnt exists', 'ultimate-member' ) );
    		}
    	}
    }
    Thread Starter kooogi

    (@kooogi)

    @missveronicatv

    Now even if a username/email exists its callback an error that the user doesnt exist

    @kooogi

    Change the || to && in the test for existing email or username.
    Both test must be false for not exists or make it as two separate tests.

    Thread Starter kooogi

    (@kooogi)

    OMG, how did I miss it. Ty a lot

    By the way do U have any idea how to custom error message in register form with username (user_login) field, coz there’s only “no validation” or “unique check”, cant select custom validation

    Thread Starter kooogi

    (@kooogi)

    
    add_action( 'um_submit_form_errors_hook__registration', 'my_submit_form_errors_hook__registration', 10, 2 );
    function my_submit_form_errors_hook__registration( $submitted_data, $form_data ) {
        if ( isset( $args['user_login'] ) ) {
    		if ( isset( UM()->form()->errors['user_login'] ) ) {
    			unset( UM()->form()->errors['user_login'] );
    		}
    		if ( empty( $args['user_login'] ) ) {
    			UM()->form()->add_error( 'user_login', __( 'Enter username', 'ultimate-member' ) );
    		} elseif ( username_exists( $args['user_login']) ) {
    			UM()->form()->add_error( 'user_login', __( 'The username already taken', 'ultimate-member' ) );
    		}
    	}
    }

    I tried smth like this but its doesnt work

    @missveronicatv

    • This reply was modified 1 year, 3 months ago by kooogi.

    @kooogi

    Replace first parameter in the function with $args

    Thread Starter kooogi

    (@kooogi)

    Now i feel kinda blind. However thank You very much.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Additional validation + customize error message’ is closed to new replies.