• I am working with the new 2.0 version of UM and have also bought the Social Plugin. I am trying to perform some custom validation on a field, but throwing the error is not working as it says form is null.

    add_action('um_custom_field_validation_check_fundraiser_code', 'um_action_check_fundraiser_code', 10, 3);
    function um_action_check_fundraiser_code( $key, $array, $args){
    
    	if ( isset( $args[$key] ) && strstr( $args[$key], '123' ) ) {
    		UM()->form->add_error( 'fundraiser_code', 'Your username must not contain the word 123 (TEST).' );
    		}
    
    }

    The only way I get the registration from stopping through the process is to throw the following error:

    exit( wp_redirect( add_query_arg(‘err’, ‘invalid_customer_code’) ) );

    However, it throws a generic error and nothing specific and doesn’t apply the error code/msg to a specific field. Anyone else have the same issues?

    UM() is populated but when I try and reference UM()->form (it is null)

    Thanks in advance,
    Collins

    • This topic was modified 6 years, 10 months ago by ChatBoxTX.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Same issue on our end. And after exhaustive searching it seems this is common issue. The code shown in the official documentation on how to Apply custom validation to a field also throws the error you are describing.

    add_action('um_submit_form_errors_hook_','um_custom_validate_username', 999, 1);
    function um_custom_validate_username( $args ) {
    	global $ultimatemember;
    	
    	if ( isset( $args['user_login'] ) && strstr( $args['user_login'], 'admin' ) ) {
    		$ultimatemember->form->add_error( 'user_login', 'Your username must not contain the word admin.' );
    	}
    }
    

    After spending a few hours troubleshooting we found we had to use:

    $ultimatemember->classes['form']->add_error( 'user_login', 'Your username must not contain the word admin.' );
    

    So in your case, try changing:

    UM()->form->add_error( 'fundraiser_code', 'Your username must not contain the word 123 (TEST).' );
    

    to:

    UM()->classes['form']->add_error( 'fundraiser_code', 'Your username must not contain the word 123 (TEST).' );
    

    Best of luck!

    Thread Starter ChatBoxTX

    (@cdeloach)

    Awesome info! Thanks for your help!

    Happy to help. Did that work for you as well?

    Thread Starter ChatBoxTX

    (@cdeloach)

    Yup, the last one. And it got the error msg on the field which the redirect was not doing. Someone needs to update the docs

    Hello friends , the code :

    $ultimatemember->classes[‘form’]->add_error( ‘user_login’, ‘Your username must not contain the word admin.’ )

    it’s working fine! Thanks.

    zeustekdev

    (@zeustekdev)

    Anyone know how to add validation for email? Greatly appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Registration Custom Validation not working (Form null)’ is closed to new replies.