• Resolved darkstar123456

    (@darkstar123456)


    Hello,

    I am using Ultimate Member on a website and since the last update, the registration form stopped working.

    It took me hours to find out why but it comes from my custom validation rules and the fact that you are using isset() of empty()

    In my registration form I have required fields that should not be required in some cases.
    So in my hooks, I am looking for errors and I unset them the field is valid for that case :

    add_action( 'um_custom_field_validation_is_required_autre_secteur', function ( $key, $array, $args ) {
    if ( ! empty( $args['secteurs'] ) && $args['secteurs'] !== 'Autre' && $args['secteurs'] !== '17' ) {
    if ( UM()->form()->has_error( $key ) ) {
    unset( UM()->form()->errors[ $key ] );
    }
    }
    }, 999, 3 );

    The problem with that is that, at this point, UM()->form()->errors is set

    Now if I look at the function that manage the submit of the registration form um_submit_form_register() I can see on the first line that if errors si set, the function bail out

    // ultimate-member/includes/core/um-actions-register.php
    function um_submit_form_register( $args, $form_data ) {
    if ( isset( UM()->form()->errors ) ) {
    return;
    }

    // Do the registration
    }

    I think it will be better to check EMPTY() instead of ISSET()

    // ultimate-member/includes/core/um-actions-register.php
    function um_submit_form_register( $args, $form_data ) {
    // Bail out only if empty
    if ( empty( UM()->form()->errors ) ) {
    return;
    }

    // Do the registration
    }

    For the moment, to resolve my problem, I have added the snippet below into each my custom validation rules… but it’s not very pretty :/

    if ( empty( UM()->form()->errors ) ) {
    unset( UM()->form()->errors );
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Yurii

    (@yuriinalivaiko)

    Hello @darkstar123456

    The errors property is null if there are no errors. This property is an array if there are errors. The plugin never removes errors that have been added, so using isset() is correct.

    Please do not remove error messages. I recommend you change your custom validation rules, so that instead of removing the error message, you don’t add it at all.

    If you wish to remove all error messages, you should set the errors property to null. You don’t need to do this into each custom validation rule, just do this once after all validation rules.

    add_action( 'um_submit_form_errors_hook', function( $submitted_data, $form_data ) {
    if ( empty( UM()->form()->errors ) ) {
    UM()->form()->errors = null;
    }
    }, 20, 2 );

    Regards

    Thread Starter darkstar123456

    (@darkstar123456)

    Hello @yuriinalivaiko

    Thank you for your answser.

    I find using the isset() function very unintuitive in this context, but it doesn’t matter.
    Thanks for the code snippet, which saves me from having to write the same thing over and over again. ^^

    Best regards

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

The topic ‘Register not working with custom validation’ is closed to new replies.