From 7eb68360c47eeb62a0d663b5088ca205637daadb Mon Sep 17 00:00:00 2001 From: Vijendra Jat Date: Thu, 9 Apr 2026 14:13:41 +0530 Subject: [PATCH] Prevent profile form submission when required fields are empty On the user profile screen, required fields (Email and Nickname) are validated server-side. If a user spends time filling out many fields but leaves a required field empty and submits, WordPress returns a server-side error and all unsaved field values are lost. This fix adds client-side validation to the profile form using the existing validateForm() function already available in common.js. The form-required class is added to the Nickname and Email rows in user-edit.php, and a submit event handler is added to #your-profile in user-profile.js that calls window.validateForm() to block submission and highlight the empty fields. Server-side validation is unchanged and remains the security boundary. Only the #your-profile update form is targeted, matching the server-side behavior where Nickname is only required on update. --- src/js/_enqueues/admin/user-profile.js | 4 ++++ src/wp-admin/user-edit.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/js/_enqueues/admin/user-profile.js b/src/js/_enqueues/admin/user-profile.js index ce680ef4c4298..3d1c9ac95ad32 100644 --- a/src/js/_enqueues/admin/user-profile.js +++ b/src/js/_enqueues/admin/user-profile.js @@ -496,6 +496,10 @@ isSubmitting = true; }); + $( '#your-profile' ).on( 'submit', function() { + return window.validateForm( this ); + } ); + $form = $( '#your-profile, #createuser' ); originalFormContent = $form.serialize(); }); diff --git a/src/wp-admin/user-edit.php b/src/wp-admin/user-edit.php index 6810425c77dc8..38388e324e0f6 100644 --- a/src/wp-admin/user-edit.php +++ b/src/wp-admin/user-edit.php @@ -506,7 +506,7 @@ - + @@ -560,7 +560,7 @@

- +