1. Forms
1.1. The form element
There are, semantically speaking, many types of forms on the Web. Here is a short list of different forms a user hits on a daily basis:
- Search
- Log in
- Register
- Order
- Shopping basket
- Pay
- Reset my password
- Contact and feedback
- Newsletter subscription
- etc.
Most of these forms do materialize as a <form>
element in the markup of their Web page host but not always.
Avoid, unless absolutely necessary, form field
elements having no enclosing <form>
elements.
Detection of the typology of a form requires, if there is no
enclosing <form>
element, to find the deepest common ancestor of geographically
aggregated form field elements and to use it as a form. This is
expensive, error-prone, and too often semantically wrong.
1.2. The data-form-type attribute for form elements
A number of [html]
or [WAI-ARIA-1.1] attributes carried
by <form>
elements can hold human- or
machine-readable information that go beyond purely programmatic or
stylistic data. For instance:
name
id
title
action
aria-label
- etc.
To determine the type, semantically speaking, of a given Web form, a code (for instance living inside a [WebExtension]) has no other choice than trying to read and understand these arbitrary human- or machine-readable data. This is doable but remains extremely expensive, error-prone and, all in all, an educated guess.
We are then suggesting a new attribute compatible with the [html] specification: the data-form-type
attribute.
Add a data-form-type
attribute to all your forms
The data-form-type
attribute carries type information
about the form carrying the attribute. It is an unordered list of
comma-separated case-insensitive values. Its default value is "other
".
The valid values for this attribute are:
billing
- change_password
contact
forgot_password
- identity
login
newsletter
other
payment
register
search
- shopping_basket
shipping
Additionnally, the step
value should be added to the data-form-type
attribute if
the current form is only one step in a multi-form unique process, and
the final
value should be added alongside the step
value if the
current form is the last step in a multi-form unique process.
The billing
value represents a form allowing the user to enter a billing address.
The change_password
value represents a form allowing the user to change his/her credentials
for the current Web page/Web site.
The contact
value represents a form allowing to contact the editors of a Web
page/Web site and/or provide feedback.
The final
extra value should be added to other values if the current form is the
last step in a multi-form process where all forms have the same data-form-type
(except final
value).
The forgot_password
value represents a form allowing a user to retrieve his/her current
credentials for the current Web page/Web site.
The identity
value represents a form allowing a user to provide identity details (ID,
passport or more general information like name, birthdate, etc) outside
of another form type (eg. register
or contact
)
to the current Web page/Web form.
The login
value represents a form allowing a user to authenticate himself/herself
on a given Web page/Web site, providng credentials.
The newsletter
value represents a form allowing a user to suscribe to or unsubscribe
from a newsletter sent by email.
The other
value is used when no other value of the data-form-type
attribute can accurately represent the form.
The payment
value represents a form allowing a user to enter payment information
(credit card, IBAN, etc.).
The register
value represents a form allowing a user to create an account on a given
Web page/Web site.
The search
value represents a search form, basic or advanced.
The shipping
value epresents a form allowing the user to enter a shipping address.
The shopping_basket
value represents a form allowing a user to visualize the current
contents of his/her shopping basket.
The step
extra value should be added to other values if the current form is only
one step in a multi-form process where all forms have the same
data-form-type
(except final
value).
The following real-life form should carry data-form-type="register"
The following real-life form should carry data-form-type="login,step"
The following real-life form should carry data-form-type="search"
1.3. The data-form-type attribute for form field elements
Similarly, it can be extremely difficult to detect the type,
semantically speaking, of a given for field like a <input>
or <button>
element contained in a form. Let's take
some real-life examples.
Most Web sites implement the Show/Hide buttons inside password fields in two different ways:
- the
type
attribute of the<input>
element switches from "password
" to "text
" and back, - a deck of two strictly overlapping
<input>
elements, one withtype="password"
and the other withtype="text"
, sharing the same value; the Web page shows only the one corresponding to the user's request.
In both cases, it can be extremely complex for a code to understand
that an <input type="text"">
element is indeed a
password field if nothing in its context (attributes, label, etc.)
indicates it.
The French IRS's Web site has a login form that is pretty common for such gouvernmental Web sites. The user must use an ID that is a "tax number" or a fiscal reference to log in. Here is a screenshot and the markup:
As you can see, it is pretty difficult to understand from the markup of the form that the input field should host a user ID:
- the
type
attribute of the element indicates a telephone number... That's a hack used by too many Web sites to show the numeric keyboard on mobile devices. Another value of thetype
attribute, the "number
" value, could be used too but unfortunately it often renders spinbuttons for +1 increase and -1 decrease alongside the input field. - the
<label>
for the input field reads "Numéro fiscal" ("Tax ID" in english) but "Numéro" ("number" in english) is consistent with thetype="tel
" carried by the input element - the input element itself carries another conflicting piece of
information as an attribute
autocomplete="username"
We are then proposing to reuse the data-form-type
attribute described above to provide client codes with semantic
information about the real usage of each form field element.
Add a data-form-type
attribute to all your form field elements
The data-form-type
attribute carries type information
about the form field element carrying the attribute. It is an
unordered list of comma-separated case-insensitive values and extra
values. Its default value is "other
".
The valid values for this attribute are the following ones (for each item, the sublist defines the valid extra values for that value):
action
- Action extra values
address
- Location extra values
- Code extra values
- ID extra values
- Payment extra values
- Location type extra values
- Partial extra values
age
company
consent
- Consent extra values
date
email
- Repetition extra values
- Email extra values
id_document
name
- Name extra values
- ID extra values
- Title extra values
- Payment extra values
- Location type extra values
other
otp
- Partial extra values
password
- Repetition extra values
payment
- Payment extra values
- Location type extra values
- Partial extra values
phone
query
title
- Title extra values
username
- Repetition extra value
website
Values
The action
value represents a form field or a link that serves as submission button
or UI element allowing to submit the form or move to the next part in
the form.
The address
value represents a form field element that can contain an physical or
postal address or a part of a physical or postal address.
The age
value represents a form field that can contain an age or define a range
of ages (eg. between 40 and 49 years old).
The company
value represents a form field that can contain information about a
company, corporation, professional organization, etc.
The consent
value represents a form field that is either a consent about Terms,
Policies, etc. or a link to such documents.
The date
value represents a form field element that can contain a date or part of
a date.
The email
value represents a form field element that can contain an email address
or a part of an email address.
The id_document
value represents a form field element that can contain information about
an identity document such as an ID card, a passport, a driving license,
etc.
The name
value represents a form field element that can contain the name of an
individual or organization or a part of the name of an individual or
organization.
The other
value represents a form field element that cannot be classified using
another value. This is the default value for the atttribute.
The otp
value represents a form field element that can contain a One-Time
Password, for instance an confirmation code the user receives on his
mobile phone.
The password
value represents a form field element that can contain a password or a
passphrase.
The payment
value represents a form field element that can contain information about
a payment method like a bank account, a credit card or wire transfer
information.
The phone
value represents a form field element that can contain a phone number of
a part of a phone number.
The query
value represents a form field element that can contain the subject of a
search request.
The title
value represents a form field element that can contain title or gender
information about an individual.
The username
value represents a form field element that contains a login name, a
pseudo, etc. used to authenticate a user on a website.
The website
values represents a form field element that can contain a URL.
Extra values
- the
change_password
extra value represents a button or link that, when activated, allows users to change their passwords - the
forgot_login
extra value represents a button or link that, when activated, allows users to retrieve the login part of their credentials. - the
forgot_password
extra value represents a button or link that, when activated, allows users to reset their passwords - the
login
extra value represents a button or link that, when activated, allows users to authenticate themselves - the
logout
extra value represents a button or link that, when activated, allows users to log out from a website - the
my_account
extra value represents a button or link that, when activated, allows users to access their account on a website - the
next
extra value represents a button or link that, when activated, allows users to continue a process across multiple consecutive forms - the
register
extra value represents a button or link that, when activated, allows users to register/create an account onto a website - the
search
extra value represents a button or link that, when activated, sends a search query to the server. - the
subscribe
extra value represents a button or link that, when activated, allows users to subscribe to a newsletter.
Code extra values
- the
code
extra value represents an access code like the activation code of a credit card or an access code to a building
Company extra values
- The
company_name
extra value represents the full name of a company
Consent extra values
- the
newsletter
extra value represents a form field element allowing the user to express consent or dissent to receive a newsletter - the
privacy_policy
extra value represents either a form field element allowing the user to express consent or dissent to a Privacy Policy, or a link to such Privacy Policy - the
rememberme
extra value represents a form field allowing users to specify they want to keep their session open and avoid future login steps - the
terms
extra value represents either a form field element allowing the user to express consent or dissent to legal documents like Terms of Services, or a link to such documents
Date extra values
- the
birth
extra value indicates the information is relative to a birth date - the
day
extra value represents the day part of a date - the
expiration
extra value indicates the information is relative to an expiration date - the
issue
extra value indicates the information is relative to a date of issue - the
month
extra value represents the month part of a date - the
year
extra value represents the year part of a date
Email extra values
- the
local_part
extra value represents the part of an email address that precedes the @ sign - the
domain_part
extra value represents the part of an email address that follows the @ sign
ID extra values
- the
citizenship
extra value represents a citizenship - the
drivers_license
extra value represents information about a Driver's License - the
id_card
extra value represents information about an Identity/Citizenship Card - the
passport
extra value represents information about a Passport - the
ssn
extra value represents information about a Social Security Number - the
tax
extra value represents a tax reference like an IRS number in the US or a "Numéro fiscal" in France
Location extra values
- the
address_name
extra value represents a user-defined name for a given address - the
box
extra value represents for instance the PO Box of an address - the
building
extra value represents the building part of an address - the
city
extra value represents the name of a city or town - the
country
extra value represents the name of a country in an address - the
departement
extra value represents the name of code of a French "département" in an address in France (see also region and state below) - the
door
extra value represents the number a door or appartment in an address - the
floor
extra value represents the floor part of an address - the
region
extra value represents the name of a region in an address, for instance Île-de-France in France or Sicily in Italy. - the
stairway
extra value represents the identification of a stairway in an address - the
street
extra value represents partial or total information about a street name in an address - the
street_number
extra value represents the street number of an address - the
street_type
extra value represents the type of the street (rue, boulevard, gata, driveway, etc.) - the
zip
extra value represents the zip or postal code of an address
- the
billing
extra value represents information about a billing address - the
shipping
extra value represents information about a shiping address
Name extra values
- the
first
extra value represents the first name part of a name - the
last
extra value represents the last name part of a name - the
maiden
extra value represents a secondary family name like a maiden name - the
middle
extra value represents the middle name part of a name - the
middle_initials
extra value represents the initials of the middle name part of a name
Partial extra values
- the
part
extra value indicates the form field element contains only part of an information. - the
extra
extra value represents extra information that complements other better classified information
Payment extra values
- the
alias
extra value represents a user-defined name for a bank account or credit card; it's not part of the bank account or payment information per se. - the
bank_account
extra value represents information about a bank account - use the secondary extra value
bank_code
to indicate the bank code part of a bank account - use the secondary extra value
part
if the bank code is divided in several parts (for instance in the case of bank identifier followed by a branch code) - use the secondary extra value
number
to indicate the account number part of a bank account number - the
bank_name
extra value represents the human-readable name of the bank or financial organization holding a bank account. - the
bic
extra value represents information about the BIC part of a bank account identification - the
credit_card
extra value represents information about a credit or debit card - use the secondary extra value
number
to represent a credit or debit card number - the
cvv
extra value represents a validation code like the CVV/CVV2 codes for credit cards or checksum information for account numbers - the
iban
extra value represents information about the IBAN part of a bank account identification - the
swift
extra value represents information about the SWIFT part of a bank account identification - the
type
extra value represents the type of some payment information, eg. Visa, Paypal, Wire Transfer, etc.
Phone extra values
- the
country
extra value represents the country code part of a phone number - the
mobile
extra value indicates a phone number is a mobile phone number - the
prefix
extra value represents a prefix, that is not a country code, composing a phone number - the
type
extra value represents a form field that can contain the type of a phone number (mobile, landline, fax, etc.) - the
suffix
extra value represents a suffix composing a phone number
Repetition extra values
- the
confirmation
extra value represents a field that is present in the form to confirm the value of another field - the
new
extra value represents new user-defined data like a new password, a new address, etc. - the
secondary
extra value represents extra user data that are to be used only if the form also contains the similar primary user data
Title extra values
- the
job
extra value indicates the information is about a job title - the
gender
extra value indicates gender information
Use the "other" value to ignore a field
Should you need to make a form field "ignored" by client codes, you
can set its data-form-type
attribute to "other
".
Examples
Subscription page for the Washington Post in April 2020:
On that page, the form should have a data-form-type
attribute set to "register
".
The two radio buttons at the top don't need to be tagged with a data-form-type
since they don't belong to the form, markup-wise.
The first input field should have a data-form-type
attribute set to "email
". The second should have the
attribute set to "password
" and the third to "password,confirmation
".
MyFrys page for frys.com.
On that page, there are two forms. The first one, on the left-hand
side of the screen should have a data-form-type
attribute set to "login
". The second one, on the
right-hand side of the screen should have a data-form-type
attribute set to "register
".
The attribute values for the various input fields should be:
Login form | |
email |
|
Password | password |
Checkbox | other |
Button | action,login |
Register form | |
First name | name,first |
Last name | name,last |
Email address | email |
Confirm email address | email,confirmation |
Create password | password |
Confirm password | password,confirmation |
Zip code | address,zip |
Checkbox | consent,newsletter |
Button | action,register |
Register form at darty.fr.
On that page, the form should have a data-form-type
attribute set to "register
".
The attribute values for the various input fields should be:
Particulier | other |
Professionnel | other |
Mme. | title,gender |
M. | title,gender |
Nom | name,last |
Prénom | name,first |
Adresse email | email |
Confirmer adresse email | email,confirmation |
Mot de passe | password |
Confirmer le mot de passe | password,confirmation |
Date de naissance | date,birth |
Téléphone (mobile) | phone,mobile |
Téléphone (fixe) | phone |
Adresse | address |
Nom de la société, cedex... | address,extra |
Bât. | address,building |
Esc. | address,stairway |
Étage | address,floor |
Porte | address,door |
Pays | address,country |
Code postal | address,zip |
Ville | address,city |
Checkbox (SMS) | consent,newsletter |
Checkbox (email) | consent,newsletter |
Opt-out | consent,newsletter |
Button | action,register |
Login form at twitter.com.
On
that page, the form should have a data-form-type
attribute
set to "login
".
In this form, the first field should have a data-form-type
attribute set to "phone,email,username
" and the second
one to "password
".
A. References
A.1. Normative references
- [html]
- Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
- [WAI-ARIA-1.1]
- Joanmarie Diggs; Shane McCarron; Michael Cooper; Richard Schwerdfeger; James Craig. 14 December 2017. W3C Recommendation. URL: https://www.w3.org/TR/wai-aria-1.1/
A.2. Informative references
- [WebExtensions]
- https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions