• Resolved Riddhi Mehta

    (@riddhiehta02)


    Hello Team,

    I have used this plugin and now I want to add custom validation on my field for the registration field.

    I have sued the code which provided on the the site reference.

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

    I used this code :

    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.’ );
    }
    }

    But it fires the error this:

    “Uncaught Error: Call to a member function add_error() ”

    So, How can I used this can you please explicit me in brif. And please give me the solution that how can I add the custom validation on my form field.

    Thanks,
    Riddhi Mehta

Viewing 1 replies (of 1 total)
  • Thread Starter Riddhi Mehta

    (@riddhiehta02)

    Hello Team,

    I found the solution for this task,

    We used this for custom error,

    instead of this,

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

    We have to use this one,

    UM()->form()->add_error( ‘user_login’, ‘Your username must not contain the word admin.’ );

    And the validation will added.

    Thanks,
    Riddhi Mehta

Viewing 1 replies (of 1 total)
  • The topic ‘Add Custom validation to the field’ is closed to new replies.