Make WordPress Core

Opened 3 months ago

Last modified 11 days ago

#54394 new feature request

Add functions for required fields indicator and message

Reported by: sabernhardt Owned by:
Milestone: 6.0 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch required-fields
Focuses: accessibility Cc:

Description (last modified by sabernhardt)

Required fields should include a visual indicator, plus a legend when using a star or similar character for multiple fields.

Having a set of return and echo functions to create strings for both the indicator and a default explanation could help in some core implementations such as #34860, as well as with plugins and themes (if their minimum WordPress version includes these functions).

Attachments (3)

54394.patch (2.3 KB) - added by sabernhardt 3 months ago.
basic concept
53494.2.patch (4.3 KB) - added by sabernhardt 3 months ago.
using a second argument to determine whether to echo each function instead of creating two more functions, plus including adjustments to comment template file
53494.3.patch (2.9 KB) - added by sabernhardt 11 days ago.
updating comments form example after r52200

Download all attachments as: .zip

Change History (13)

@sabernhardt
3 months ago

basic concept

#1 @sabernhardt
3 months ago

The names of the functions could change; these are what I have for now:

get_required_field_indicator
the_required_field_indicator

get_required_field_message
the_required_field_message

Each of these functions has a $space_before argument to define whether the tag should have a space before it and which kind of space (someone may want non-breaking or similar).

I may have overused the escape functions, but the first patch is mainly for the concept.

#2 @sabernhardt
3 months ago

  • Keywords has-patch required-fields added

@sabernhardt
3 months ago

using a second argument to determine whether to echo each function instead of creating two more functions, plus including adjustments to comment template file

#3 @sabernhardt
3 months ago

Or these could be two functions, with the echo selection as a second parameter:

wp_required_field_indicator( $space_before = ' ', $echo = false )
wp_required_field_message( $space_before = ' ', $echo = false )

#4 @sabernhardt
3 months ago

The required-field-message class in these patches would be more generic than the comment-required-message class that's now in the comment template. (Or perhaps it could be wp-required-field-message if the function name is wp_required_field_message.)

Last edited 2 months ago by sabernhardt (previous) (diff)

#5 @sabernhardt
3 months ago

  • Description modified (diff)

This ticket was mentioned in Slack in #accessibility by sabernhardt. View the logs.


2 months ago

This ticket was mentioned in Slack in #accessibility by sabernhardt. View the logs.


2 months ago

This ticket was mentioned in Slack in #accessibility by ryokuhi. View the logs.


2 months ago

#9 @ryokuhi
2 months ago

  • Milestone changed from Awaiting Review to 6.0

This ticket was reviewed today during the accessibility team's bug-scrub.
This ticket already has a patch, so we're milestoning it for 6.0.
The functions introduced with this ticket will probably be useful to solve other open tickets and in other parts of WordPress core: a starting point could be reviewing which required fields can benefit from these functions.
It still has to be decided if such a review should be done here or in a new ticket.

@sabernhardt
11 days ago

updating comments form example after r52200

#10 @sabernhardt
11 days ago

  • Description modified (diff)

If editing the Comments form template is appropriate, some of these other existing cases might be good to update as well:

Note: See TracTickets for help on using tickets.