Creating webforms

The most monotonous entities in the knownuseful for fields such as social security or phone
universe, forms, are a staple of every webnumbers containing a character limit for each input
programmer's balanced diet. Whether we like them orfield. For example, after a user enters the area code
not, forms are the gatekeepers to our site's goodiesof a phone number, the form automatically tabs to
and often their design alone determines whether athe next input box allowing the user to continue
user will try what you're selling or simply walk away.entering their phone number without interruption.
Without pomp or circumstance, here are ten tips toTo flag an input element to be autotabbed, you only
transform your plain vanilla into double chocolateneed to include three things in your markup: tabindex,
chunk with marshmallows.className of autoTab and maxlength.
1. Remember Your Markup We've notice a lot ofField Information It's always good policy to provide
people forgetting to use the tools that are alreadyinformation describing a field's requirements and
made accessible to them by the very medium thatrestrictions. How else is the user going to know a
they work in. And so we've highlighted a few HTMLpassword must have 3 capital letters, an exclamation
elements below that are made especially for forms.point and be somewhere between 6 and 17
Just to refreshen the ol' web noggin.characters long? Inspired by the forms used over at
Label A label is used to attach information to aTangent, we came up with some additional
control. If you focus on a label, its associated controlsuggestions.
will gain focus. This is useful when a user clicks on aStore all related information in a fields label tag. You
label name and the associated field gains focus.can place a className of required, an accesskey, and
"The FIELDSET element allows authors to groupa descriptive title in there, so that all information is in
thematically related controls and labels. Groupingone place. This makes it easier to roganize, and easier
controls makes it easier for users to understand theirfor JavaScript to pull from.
purpose while simultaneously facilitating tabbingWe choose to use onfocus instead of onmouseover
navigation for visual user agents and speechwhen displaying information to the user. While mostly
navigation for speech-oriented user agents. Thepersonal preference, it is still nice to know that the
proper use of this element makes documents moreproper information will be displayed on the field with
accessible." "The LEGEND element allows authors tofocus rather than where the mouse is.
assign a caption to a FIELDSET. The legend improvesIt is easier to give labels an id similar to the field they
accessibility when the FIELDSET is renderedrelated to. For example, if a field is named fname, call
non-visually." "This attribute specifies the position ofthe label lfname. It makes things much easier on the
the current element in the tabbing order for theJavaScript side to pull information. You can see the
current document. This value must be a numberlabels title being accessed below: Error Displays When
between 0 and 32767. User agents should ignorea user makes a mistake, it's your duty to show them
leading zeros.The tabbing order defines the order inerrors quickly and efficiently. Here are some ideas to
which elements will receive focus when navigated bymake your forms display errors better: Don't just
the user via the keyboard. The tabbing order mayshow the user one error. If they left 3 required fields
include elements nested within other elements." "Thisblank, make sure that you tell them they have three
attribute assigns an access key to an element. Anerrors, this way they can correct them all in one fell
access key is a single character from the documentswoop.
character set. Note. Authors should consider the inputProvide as much information to the user beforehand
method of the expected reader when specifying anas possible. Examples of this would be marking a field
accesskey." Password By adding type="password" toas required, or explaning the minimum password
your input field, characters entered will belength (See #2 above).
transformed into a series of asterisks.Be aware of the three validation options at your
"Application designers should note that thisdisposal: 1) you can give responsive feedback straight
mechanism affords only light security protection.from the JavaScript. The user benefits from instant
Although the password is masked by user agentsfeedback, but you will have to duplicate your
from casual observers, it is transmitted to the servervalidation functions on the client and server. 2) You
in clear text, and may be read by anyone withcan provide Degradable Ajax Validation that gets rid
low-level access to the network." 2. CSS This isn'tof the duplicated code, but increases the server load.
new, but CSS can turn your eye sore of a form into3) You may validate only on form submit which
something negative fugly. There is no need toleaves you with no duplicated code, no additional
reinvent the wheel here, so check out the followingserver load, and unfortunately, no instant feedback.
sources on enhancing your form with some CSS andPut some effort into the display of your error
a little Javascript.messages. Make them bold, noticable, and throw in a
Style Those Buttons - The Man In Blue shows usbit of creativity. It is also best to stick with colors
how to make those buttons not look so cheap.that the user is comfortable with:red for errors,
Niceforms - Niceforms does a great job of turningyellow for warnings, green for success. Obviously
that ugly form into something much more tolerableyou can switch those up based on your evaluation,
using a little CSS action.but going to far and making an error message pink
Hide Optional Fields - In this example, a little CSS andcould cause some confusion.
Javascript is used to make a form better looking and6. Postbacks There is nothing worse than filling out a
more usable.form, encountering an error, and having to retype all
CSS Forms - Jeff Howdens shows us how to createof your information all over again. In order to save
a well layed out and styled form without using tables.your users from needless frustration, we need to
AutoTab When navigating through a form, the userensure that all data is preserved. This means if there
traditionally presses the tab button in order tois an error, the fields should be repopulated. If we
advance to the next form control. This AutoTabhave a multistep form, back and forward navigation
function automatically sets the focus to the nextshould also keep the form populated. A common
control after the control's maxlength is reached. Thisapproach is to set a form's action to it's current URL.
allows for the user to no longer manually tab throughThat way, you can read in the form value and
fields with a maxlength. This function is particularlypopulate the fields immediately if there is an error.