-
Notifications
You must be signed in to change notification settings - Fork 7
Adds topic required form fields to the Web forms section #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f2cb05b
adds topic required form fields
rianrietveld a4d8b83
Apply suggestions from text review
rianrietveld 1c128d5
change example to an easier one
rianrietveld 2a7bf3e
fix uneven spaces
rianrietveld 933fc9c
Merge branch 'main' of github.com:wpaccessibility/wp-a11y-docs into 1…
rianrietveld f186ba9
Apply suggestions from text review
rianrietveld 0250035
Apply suggestions from text review
rianrietveld 2c63807
typo
rianrietveld 47c8400
Merge branch 'main'
rianrietveld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| title: Required fields | ||
| layout: default | ||
| parent: Web forms | ||
| nav_order: 8 | ||
| --- | ||
|
|
||
| # Indicate required fields in forms | ||
|
|
||
| Clearly indicate to the user whether a form field is required to fill out or not. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Then the user knows which information they must provide to submit a form. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You have two options: | ||
rianrietveld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 1. By visually marking required fields. | ||
| 2. By visually marking non-required fields. | ||
|
|
||
| Both are fine, as long as you are consistent within the form and, if possible, also within all forms on your website. | ||
|
|
||
| Always place the explanation of how you indicate this above the form, so the user knows beforehand what to expect when completing it. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| title: Mark non-required fields | ||
| layout: default | ||
| parent: Required fields | ||
| nav_order: 3 | ||
| --- | ||
|
|
||
| # Option 2: Marking only the non-required form fields | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Clearly indicate to the user if a form field is optional. | ||
|
|
||
| Assuming that you only request essential information in forms, most fields will be required. Then, non-required fields are the exception. You can choose to mark only the optional fields visually. Do this by informing the user above the field and by including the text '(optional)' in the label for non-required fields. | ||
|
|
||
| ## Example | ||
|
|
||
| <figure> | ||
| <img src="{{site.baseurl}}/assets/images/mark-non-required-form-fields.png" alt="Screenshot form indicating non-required fields"> | ||
| <figcaption> | ||
| In this screenshot: Above the form the text: "All questions are required except the questions marked as (optional)". | ||
| This information is also in the label text: Your Pronouns (optional). | ||
| </figcaption> | ||
| </figure> | ||
|
|
||
| {: .alert } | ||
| **Note for developers**: for screen reader users the indication if a field is required must be added in the code with a form field. Read [Mark if a form field is required for screen readers]({{site.baseurl}}/docs/topics/forms/required/required-screen-readers/) about how to do this. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Indication non-required fields in WordPress form plugins | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| {: .info } | ||
| We'd like to invite people familiar with form plugins to help us add instructions for WordPress form plugins. Like possibilities, settings and screenshots. | ||
| Please [contact us]({{site.baseurl}}/docs/contact/) if you want to help us with this additional content. | ||
|
|
||
| ## Related WCAG Success Criteria | ||
|
|
||
| By indicating required fields, you meet WCAG success criterion [3.3.2 Labels or Instructions (Level A)](https://www.w3.org/WAI/WCAG22/quickref/#labels-or-instructions). | ||
|
|
||
| ## Related pages in this documentation | ||
|
|
||
| - [Option 1: Marking only the required form fields]({{site.baseurl}}/docs/topics/forms/required/mark-required-fields/). | ||
|
|
||
| ## Resources | ||
|
|
||
| - NL Design System [Guidelines for web forms (Dutch content)](https://nldesignsystem.nl/richtlijnen/formulieren/). | ||
| - Faizan Ahmed on UX Design World [Optimizing Form Design: Marking Required and Optional Fields in a Better Way](https://uxdworld.com/form-design-required-and-optional-fields/) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --- | ||
| title: Mark required fields | ||
| layout: default | ||
| parent: Required fields | ||
| nav_order: 2 | ||
| --- | ||
|
|
||
| # Option 1: Marking only the required form fields | ||
|
|
||
| Clearly indicate to the user if a form field is required to fill out or not. Inform the user above the field how the fields are marked. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If you choose to mark the required field, include the text '(required)', or an equivalent, in the label for required fields. | ||
|
|
||
| A required field indicator can be: | ||
| - The text (required). | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - An asterisk (\*). If you use an asterisk, explain this above the form. An asterisk on the form field alone is not sufficient; not everyone has this prior knowledge. | ||
|
|
||
| ## Example | ||
|
|
||
| <figure> | ||
| <img src="{{site.baseurl}}/assets/images/mark-required-form-fields.png" alt="Screenshot form indicating required fields"> | ||
| <figcaption> | ||
| In this screenshot: Above the form the text: "*" indicates required fields. | ||
| This information is also in the label text: Your name *. | ||
| </figcaption> | ||
| </figure> | ||
|
|
||
| {: .alert } | ||
| **Note for developers**: for screen reader users the indication if a field is required must be added in the code with a form field. Read [Mark if a form field is required for screen readers]({{site.baseurl}}/docs/topics/forms/required/required-screen-readers/) about how to do this. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Indication required fields in WordPress form plugins | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Gravity Forms | ||
|
|
||
| Gravity Forms adds the possibility to select "Required" with each form field. In the form settings you can choose the type of Required Field Indicator. The explanation of this indicator is added automatically above the form. | ||
|
|
||
| ### Other WordPress form plugins | ||
|
|
||
| {: .info } | ||
| We'd like to invite people familiar with form plugins to help us add instructions for WordPress form plugins. Like possibilities, settings and screenshots. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Please [contact us]({{site.baseurl}}/docs/contact/) if you want to help us with this additional content. | ||
|
|
||
| ## Related WCAG Success Criteria | ||
|
|
||
| By indicating required fields, you meet WCAG success criterion [3.3.2 Labels or Instructions (Level A)](https://www.w3.org/WAI/WCAG22/quickref/#labels-or-instructions). | ||
|
|
||
| ## Related pages in this documentation | ||
|
|
||
| - [Option 2: Marking only the non-required form fields]({{site.baseurl}}/docs/topics/forms/required/mark-non-required-fields/). | ||
|
|
||
| ## Resources | ||
|
|
||
| - NL Design System [Guidelines for web forms (Dutch content)](https://nldesignsystem.nl/richtlijnen/formulieren/). | ||
| - Faizan Ahmed on UX Design World [Optimizing Form Design: Marking Required and Optional Fields in a Better Way](https://uxdworld.com/form-design-required-and-optional-fields/) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| title: Mark required for screen readers | ||
| layout: default | ||
| parent: Required fields | ||
| nav_order: 4 | ||
| --- | ||
|
|
||
| # Mark a required form field for screen readers | ||
|
|
||
| Screen reader users will have the field announced as required by the HTML attributes `aria-required` or `required` on the form field. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Basic HTML examples | ||
|
|
||
| ### Using aria-required="true" | ||
|
|
||
| ```html | ||
|
|
||
| <label for="name">Your name (required)</label> | ||
| <input | ||
| id="name" | ||
| type="text" | ||
| name="name" | ||
| autocomplete="name" | ||
| aria-required="true" | ||
| aria-invalid="false" | ||
| /> | ||
| ``` | ||
|
|
||
| ### Using required | ||
|
|
||
| ```html | ||
| <label for="name">Your name (required)</label> | ||
| <input | ||
| id="name" | ||
| type="text" | ||
| name="name" | ||
| autocomplete="name" | ||
| required | ||
| aria-invalid="false" | ||
| /> | ||
| ``` | ||
|
|
||
| The disadvantage of using `required` is, that it triggers the [client-side form validation](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation) of the browser. | ||
|
|
||
| At the time of writing, this validation does not meet WCAG accessibility guidelines. The error messages are not specific enough, they disappear after a few seconds, and they currently lack sufficient screen reader support. | ||
rianrietveld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If you decide to use `required`, also use `novalidate` on the form element to prevent the browser's form validation from kicking in and enable you to handle validation server-side. | ||
rianrietveld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```html | ||
| <form action="some-url" novalidate> | ||
| ``` | ||
|
|
||
| {: .info } | ||
| Note: the use of `aria-invalid` will be addressed later in the section Feedback on form errors. | ||
|
|
||
| ## WCAG Success Criteria | ||
|
|
||
| By indicating required fields, you meet WCAG success criterion [3.3.2 Labels or Instructions (Level A)](https://www.w3.org/WAI/WCAG22/quickref/#labels-or-instructions). | ||
|
|
||
| ## Resources | ||
| - MDN [aria-required](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-required). | ||
| - MDN [HTML attribute: required](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/required). | ||
| - W3C [Validating Input](https://www.w3.org/WAI/tutorials/forms/validation/). | ||
| - NL Design System [Guidelines for web forms (Dutch content)](https://nldesignsystem.nl/richtlijnen/formulieren/). | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.