Opened 9 years ago
Last modified 2 months ago
#41314 assigned defect (bug)
If the required fields are not set on user profile's save, every field's value will be dropped
| Reported by: | jackjohansson | Owned by: | jackjohansson |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Users | Version: | 4.8 |
| Severity: | normal | Keywords: | good-first-bug has-patch changes-requested |
| Cc: | Focuses: | javascript, administration |
Description
Hi,
In the user profile screen, there are some required fields such as email and nickname.
Let's say I have added some extra fields using edit_user_profile and show_user_profile action hooks. These fields are filled by the user, and do not have to be required.
If the user fills every field (let's say 20 fields, took 10 minutes to fill) but clears the email field and save the form, there will be shown an admin error:
ERROR: Please enter an email.
Every field that was filled by the user will be dropped, and has to be refilled.
The point is, until the required fields are empty, there is no reason to let the user save the form in the first place.
This issue has been discussed in the WordPress Development StackExchange. I've posted 3 solutions for this issue, which can be improvement or bug resolve.
Below is a link to the question on WPSE. I would be happy to write an accurate solution, in case the development team decides to push this into their future patches.
https://wordpress.stackexchange.com/q/272940/94498
King regards,
Jack
Attachments (2)
Change History (22)
#1
follow-ups:
↓ 2
↓ 20
@
9 years ago
- Component Administration → Users
- Keywords needs-patch good-first-bug added
#2
in reply to: ↑ 1
;
follow-up:
↓ 3
@
9 years ago
Replying to swissspidy:
This could be as simple as using the
validateForm()JavaScript function available in WordPress.
Thanks for the reply.
However, shouldn't this be a part of the core by default? There's no point in submitting a form that lacks required fields.
It would make some sense if the form was properly saved, but it's just submitted in order to trigger an error.
#3
in reply to: ↑ 2
@
9 years ago
Replying to jackjohansson:
Replying to swissspidy:
This could be as simple as using the
validateForm()JavaScript function available in WordPress.
Thanks for the reply.
However, shouldn't this be a part of the core by default? There's no point in submitting a form that lacks required fields.
It would make some sense if the form was properly saved, but it's just submitted in order to trigger an error.
I didn't oppose your idea. By pointing out validateForm() I'm simply suggesting a way to solve this in core.
#5
in reply to: ↑ 4
;
follow-up:
↓ 7
@
9 years ago
Replying to SergeyBiryukov:
Related: #27606
Hi,
The related ticket purposes a patch on the server side. However the issue is still standing (see the linked question).
Is a front-end solution possible in this case as @swissspidy mentioned? I've already coded a script that validates the form before sending (including extra fields added by user). If so, should I push it forward?
This ticket was mentioned in Slack in #core by welcher. View the logs.
9 years ago
#7
in reply to: ↑ 5
@
9 years ago
Replying to jackjohansson:
Replying to SergeyBiryukov:
Related: #27606
Hi,
The related ticket purposes a patch on the server side. However the issue is still standing (see the linked question).
Is a front-end solution possible in this case as @swissspidy mentioned? I've already coded a script that validates the form before sending (including extra fields added by user). If so, should I push it forward?
I'd say if you have a patch that solves the problem, go ahead and submit it
#8
@
9 years ago
I've added the initial patch for this bug. It checks nickname and password in the by jQuery, and the email by AJAX.
Currently it has a bug, you need to click the submit button twice if all of the fields are valid. There is most likely some other handler interfering, as this bug doesn't exist in a JSFiddle version of this patch.
If anyone has a moment to try it out, their feedback will be greatly appreciated.
@swissspidy @SergeyBiryukov @psykro @afercia
#9
@
9 years ago
- Keywords has-patch added; needs-patch removed
Thanks @jackjohansson I'll take a look
#10
@
9 years ago
- Summary If the required fields are not save on user save, every field's value will be dropped → If the required fields are not set on user profile's save, every field's value will be dropped
#11
@
9 years ago
- Owner set to
- Status new → assigned
Assigning to mark the good-first-bug as "claimed".
This ticket was mentioned in Slack in #core-js by naoki0h. View the logs.
7 years ago
This ticket was mentioned in Slack in #core by benharri. View the logs.
3 years ago
This ticket was mentioned in PR #11511 on WordPress/wordpress-develop by @vijendrajat.
6 months ago
#15
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.
Trac ticket: https://core.trac.wordpress.org/ticket/41314
## Use of AI Tools
#16
@
3 months ago
- Keywords needs-patch added; has-patch removed
I have tested [PR 11511](https://github.com/WordPress/wordpress-develop/pull/11511) locally, but the client-side validation is currently failing to block the form submission.
Testing Environment:
- OS: Windows
- Local Env:
wordpress-develop(Docker/Node) - Browser: Chrome (with cache disabled via DevTools)
- WordPress: 7.1-alpha (trunk)
Steps Taken:
- Fetched and applied PR #11511.
- Verified the
form-requiredclass was correctly output in the HTML foruser-edit.php. - Ran
npm run buildto compile the JavaScript. - Edited a profile: filled out a non-required field (Website) and cleared the required "Email" and "Nickname" fields.
- Clicked "Update Profile".
Results:
The client-side JavaScript does not stop the submission. The form submits to the server, the page reloads, the standard red server-side error is thrown, and all unsaved data in the other fields is wiped clean.
It appears the submit event listener added to user-profile.js isn't successfully catching the event or triggering validateForm(). This will need further debugging!
This ticket was mentioned in Slack in #core by softglaze. View the logs.
3 months ago
#18
@
3 months ago
- Keywords has-patch added; needs-patch removed
Following up on comment:16 — my earlier result was invalid due to a broken local build (I had run npm run build while the site serves src/, so no compiled JS was loaded and all core JS 500'd; the failure I reported was an environment artifact, not the PR).
After a clean npm ci + npm run build:dev, retested PR 11511 (Windows, Docker, Chrome, 7.1-alpha trunk):
✅ With Nickname and/or Email cleared: submission is blocked client-side, both fields get the error highlight, and all other unsaved values are preserved. Tested each required field individually as well.
✅ With valid data: the form saves normally in a single click.
One minor issue: each blocked submission activates the spinner next to the Update Profile button and it's never reset, so spinners accumulate and it looks like the page is stuck loading [attach your screenshot with the two circles]. Since the button is at the bottom and the error highlight is at the top of the form, there's also no visible feedback near the button about why nothing happened — resetting the spinner and moving focus to the first invalid field would help.
Overall the approach works and fixes the data-loss problem; the spinner handling looks like a small follow-up fix in the submit handler. Restoring has-patch.
softglazee commented on PR #11511:
3 months ago
#19
Tested locally on Windows (Docker, Chrome, 7.1-alpha trunk) after a clean npm ci + npm run build:dev — the fix works as intended: submission with empty Nickname/Email is blocked client-side, both fields get the error highlight, and unsaved values in other fields are preserved. Valid data saves normally in a single click.
One minor issue: each blocked submit activates the spinner next to the Update Profile button and it's never reset, so spinners accumulate on repeated attempts (screenshot attached). Since the button is at the bottom and the highlighted fields are at the top, there's no feedback near the button about why nothing happened. Suggest resetting the spinner in the handler when validation fails, and possibly moving focus/scrolling to the first invalid field.
Full test notes on the Trac ticket: https://core.trac.wordpress.org/ticket/41314#comment:17
#20
in reply to: ↑ 1
@
2 months ago
- Keywords changes-requested added
Replying to swissspidy:
This could be as simple as using the
validateForm()JavaScript function available in WordPress.
9 years later, it seems like we should be using HTML5 form validation now instead.
Related:
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
This could be as simple as using the
validateForm()JavaScript function available in WordPress.