Fix email validation logic in Ultimate Member forms

Updated conditions to handle empty and invalid email input more accurately. Ensures required emails are not skipped and includes stricter checks for existing or incorrect emails.
This commit is contained in:
Mykyta Synelnikov
2025-06-25 16:24:14 +03:00
parent 3cd647c68c
commit 4d83a7eec3
+2 -2
View File
@@ -937,9 +937,9 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) {
break;
}
if ( ! empty( $array['required'] ) && '' === $submitted_data[ $key ] ) {
if ( ! empty( $array['required'] ) && empty( $submitted_data[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'You must provide your email', 'ultimate-member' ) );
} elseif ( ! is_email( $submitted_data[ $key ] ) || email_exists( $submitted_data[ $key ] ) ) {
} elseif ( ! empty( $submitted_data[ $key ] ) && ( ! is_email( $submitted_data[ $key ] ) || email_exists( $submitted_data[ $key ] ) ) ) {
UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member' ) );
} elseif ( 'secondary_user_email' === $key && ! empty( $submitted_data[ $key ] ) && ! empty( $submitted_data['user_email'] ) && $submitted_data[ $key ] === $submitted_data['user_email'] ) {
UM()->form()->add_error( $key, __( 'The secondary email cannot be the same as primary', 'ultimate-member' ) );