Register not working with custom validation
-
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()ofempty()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()->errorsis setNow 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 );
}
The topic ‘Register not working with custom validation’ is closed to new replies.