Start using some HTML 5 form features
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 7 Aug 2009 03:32:20 +0000 (03:32 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 7 Aug 2009 03:32:20 +0000 (03:32 +0000)
commite0834ecdbf961ac6a19f60dc72588165aa2e8e86
treefbd886ab00b0071a29a8d12794a10b0c2927f99b
parent50668a7bf511c813d02b1d57c410f52c102b7569
Start using some HTML 5 form features

autofocus attribute added in some places; this looks like it's respected
by both recent Opera and recent WebKit.  Its function is
self-explanatory.  :)  I used this in a few obvious places like
Special:UserLogin and Special:ResetPass to focus the first field in the
form.  Could be used in other places too: Special:Search, etc.

required attribute added in some places.  This is only supported in
recent Opera at the moment.  Also self-explanatory: it won't allow form
submission if the field is empty.

For stuff using HTMLForm (i.e., Special:Preferences), validation will be
done for integers and floats.  Browsers that support this (recent Opera)
will not allow non-integers to be submitted for integer fields, will not
allow non-floating-point values to be submitted for float fields, and
will enforce any min/max values specified.  Opera also gives little up
and down arrows to allow the user to increment/decrement the value in
addition to letting them edit the field as text.

For HTMLForm and account creation, the email input type is used for
e-mails.  This enforces a sane set of values for e-mails (alphanumerics
plus some ASCII punctuation, with an @ in it).  Again, this is supported
only by recent Opera (yay Opera!).  Note that this is actually more
restrictive than what we currently check for on the server side; it
might be sane to tighten up our server-side checks to forbid e-mail
addresses that HTML 5 forbids.

In all cases, the extra features aren't added if $wgHtml5 is false, and
will be ignored by non-supporting browsers.

The major room for further improvement here is use of the pattern
attribute.  We can have the client refuse to submit the form unless it
matches a regex!  The HTML 5 spec says that if a title attribute is
provided, it should be a message that explains what the valid values
are and browsers should provide it to the user if the regex doesn't
match, so it's not a usability problem.  I didn't bother adding that
anywhere at this point because it would require adding new messages, but
it should be easy to do.  Note of course that HTMLForm should be updated
to verify that pattern matches on the server side as well -- this way we
have a clean, unified way of ensuring that our client and server checks
are the same.
RELEASE-NOTES
includes/HTMLForm.php
includes/Preferences.php
includes/specials/SpecialResetpass.php
includes/templates/Userlogin.php