Make WordPress Core

Opened 7 years ago

Last modified 5 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's profile jackjohansson Owned by: jackjohansson's profile jackjohansson
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Users Keywords: good-first-bug has-patch
Focuses: javascript, administration Cc:

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 (1)

#41314.patch (7.2 KB) - added by jackjohansson 7 years ago.
First patch for user update, has one bug currently

Download all attachments as: .zip

Change History (15)

#1 follow-up: @swissspidy
7 years ago

  • Component changed from Administration to Users
  • Keywords needs-patch good-first-bug added

This could be as simple as using the validateForm() JavaScript function available in WordPress.

#2 in reply to: ↑ 1 ; follow-up: @jackjohansson
7 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 @swissspidy
7 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.

#4 follow-up: @SergeyBiryukov
7 years ago

Related: #27606

#5 in reply to: ↑ 4 ; follow-up: @jackjohansson
7 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.


7 years ago

#7 in reply to: ↑ 5 @psykro
7 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

@jackjohansson
7 years ago

First patch for user update, has one bug currently

#8 @jackjohansson
7 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 @psykro
7 years ago

  • Keywords has-patch added; needs-patch removed

Thanks @jackjohansson I'll take a look

#10 @jackjohansson
7 years ago

  • Summary changed from If the required fields are not save on user save, every field's value will be dropped to If the required fields are not set on user profile's save, every field's value will be dropped

#11 @DrewAPicture
6 years ago

  • Owner set to jackjohansson
  • Status changed from new to assigned

Assigning to mark the good-first-bug as "claimed".

This ticket was mentioned in Slack in #core-js by naoki0h. View the logs.


5 years ago

This ticket was mentioned in Slack in #core by benharri. View the logs.


5 months ago

Note: See TracTickets for help on using tickets.