How to build a form – Part 2

December 21st, 2008

Part two – labelling, messaging and moving those evil legends

At the end of part one we had a form which tasted a lot like 1994. It has controls with labels all inside fieldsets but looks pants. There are a few simple steps in tidying up.

Legends

Legends are notoriously difficult to style. So I don’t even try. I wrap each legend in a span and style the span. It really works. This is particulary important for legends which are eventually going to be the visual equivalents of labels. These are legends for mult control groups such as a set of radio buttons.

Label text and required markers.

If a field must be completed we should tell our users. This is often done using an asterisk. Why? I have an interesting alternative to the ubiquitous and meaningless asterisk. I use the word “required”. Weird I know, but hey, it works and is WYWIWYG (what you write is what you get). To get these required markers to work, and allow separate styles for the label, required marker and error messages, I wrap the label text in a span and the required marker in another span. I also use the label as the required marker for scripting the validation.

This is overkill but is based on a trick I picked up from The Man in Blue. We eventually have something that looks a bit like this:
<fieldset>
<legend><span>About you</span></legend>
<div>
<label for='firstnameField' class='required'>
<span class='labelText'>First name:
<span class='requiredmarker'>(required)</span>
</span>
<input type='text' name='firstname' id='firstnameField' value=''>
</label>
</div>
</fieldset>

So far all this has done is make a mess of the markup without improving the form. Bare with me – we will get there.

Design classes

We need to add a few classes to labels and controls to hang our CSS from. If every browser supported attribute selectors we could omit some of these, but we live in a less than perfect world.

I like to set all text controls to a common width. However, there are some times when this is inappropriate (date of birth fields for example). So we need a class to apply to inputs which will have this common width. We will be making labels display as blocks, so we will also need a class to put radio and checkbox labels back to inline.

So now I have a whole pile of excess markup but a form which is usable, accessible and very flexibly stylable. The CSS then becomes a lot of fun, but that is for another instalment

Example – for a more complete example see Amnesty’s membership form

<fieldset>
<legend><span>About you</span></legend>
<div class="controlSet">
<label for='firstnameField' class='required'>
<span class='labelText'>First name:
<span class='requiredmarker'>(required)</span>
</span>
<input type='text' name='firstname' id='firstnameField' class='input' value=''>
</label>
</div>
<fieldset>
<legend><span class="labelText required">Required grouping</span></legend>
<div class="controlSet">
<input type='checkbox' name='subscribe' id='subscribeField1' value='1'> <label for='subscribeField'>Label 1</label>
<input type='checkbox' name='subscribe' id='subscribeField2' value='1'> <label for='subscribeField'>Label 2</label>
<input type='checkbox' name='subscribe' id='subscribeField3' value='1'> <label for='subscribeField'>Label 3</label>
</div>
</fieldset>
</fieldset>

Forms – a standards based how-to, part 1

December 21st, 2008

I had a phone conversation with Russ recently. He was surprised by a form on the Amnesty site. So I thought it might be worth an explanation.

Just so you know though, I am fundamentally a minimalist. I don’t like excessive design and excess mark up makes me quiver. I also think the mark up in these forms is a bit excessive.

Part one is about the markup of a form. I will base this on a rather complex example, that of Amnesty’s membership form. This is because this form has all my common building blocks in one form.

Basic controls

First of all, create your form and controls without any extraneous mark up. Text controls get wrapped in their labels, though I don’t do this with radios or checkboxen. I also place label text before the control except for radios and checkboxen where they go after the input.

Example 1: two fields with labels

<label for='nameField'>Label <input type='text' name='name' id='nameField' value=''></label>
<input type='checkbox' name='subscribe' id='subscribeField' value='1'> <label for='subscribeField'>Subscribe to our newsletter</label>

This is going to give you a form which is pretty much unusable as well as extremely ugly. The next step then is to break each control set (control and label) into separate lines. You could do this with CSS. However, this will result in a mangled mess for browsers withh CSS turned off. So here is my first bit of extraneous mark up. I wrap each control set in a div.

<div>
<label for='nameField'>Label <input type='text' name='name' id='nameField' value=''></label>
</div>
<div>
<input type='checkbox' name='subscribe' id='subscribeField' value='1'> <label for='subscribeField'>Subscribe to our newsletter</label>
</div>

The result of this is a long list of controls with no regularity of positioning of controls – still a bit of a mess but at least now a vaguely usable mess.

Joy of Sets

Each functional grouping in a form goes in a field set. There has to be a good reason to not use field sets, and forms which have more than one functional division really need them. What do I mean by functional division? A set of controls which map to a specific function or data set such as an addres set or credit card details. Grouped radio buttons or checkboxen also go in fieldsets. This breaks the form up into digestible chunks, provides a means for labelling parts of the form, and, with sets of radios/checkboxen, provides for a means of labelling the group as well as the individual items using the legend.

The fieldset should have a legend. I could rant for hours about legends. I really could. The legend is a cue to the purpose of that part of your form.

So we break the form up into sensible units and wrap each unit in a fieldset. I also use nested fieldsets where necessary. There are some issues with nested fieldsets and certain screen readers but they are more accessible than any other mechanism for labelling grouped radios.

What you have now is a more complex mess than before. Great if you can’t see but pretty horrible if you can.  This is the final form, functionality wise, however, so it is where part one ends.

Gareth Ernst

November 6th, 2008

One of my oldest friends is coming to the end of his Bachelor of Fine Arts at the National Art School, is exhibiting and taking off on his professional arts career. It is a tough gig. So go to his site at GarethErnst.com and have a look at his work (on the ‘exhibition‘ page).

Fess-up time: I got a rather fetching painting in exchange for the tiny site.

Ubuntu ate my Mini-Note

November 6th, 2008

Feeling intrepid I upgraded to Ubuntu 8.10. So, since I had been using the via chrome drivers my little computer was made very ill. Not even adding xforcevesa to the boot line would get X to start. Just a black screen with a little rectangle of white scribble in the middle.

Anyway, I keep a copy of my oldest working xorg.conf file sitting in /etc/X11 just in case. So a boot into text mode allowed me to replace the broken config with the basic vesa config. All started nicele and, as the LaptopTestingTeam wiki page will tell you it will run with vesa drivers at 16:9 (1280×720) which looks terrible.

What it didn’t tell me (at least not yesterday) was that via have released a beta of the chrome drivers for 8.10. These are 2D only but work very well for that. And you still need to fix the config (use your old via conf file – it is fine). So I do have Intrepid running nicely on the Mini-Note 2133 with decent quality 2D graphics. The nicest improvement so far is much better wireless reliability using WPA. It seems pretty flawless now and getting connected to my home network is much quicker.

Booting seems to take significantly longer than with 8.04. I haven’t timed it but I would guess 30-50% longer for a cold boot. Battery life was woeful and seems to be slightly worse now. Down from about 90 minutes with wireless to about 75 minutes – but I will keep an eye on that.

After the storm

October 23rd, 2008

sfter the storm on flickr

after the storm

Coalcliff is not famous for its beach. Actually, Coalcliff is not famous. It is really rather nice though, especially after a big spring storm.

Anatomy of html

October 23rd, 2008

A mark of any group is their shared language; and a mark of any group involved in a craft is the technical precision of their language. Brick layers, dentists, lithographers and chefs all know what each other mean when they refer to a particular item. Web professionals are no different. Most of the people working on and with the web, however, are not web professionals; even some who should be are not. For those of you who are, what I am about to describe is blindingly obvious. So you can stop reading now.

A few years ago I embarked on a mission to educate the team in my day job. I got them all to refer to all the bits that make up HTML and CSS by the correct names, This was done partly so they could explain to me what they want, partly because I am a neurotic labeller, but mostly because they wanted to be professionals in their field and so needed to use the language correctly. Things, and teams, change and just this week, for the first time in over two years, I heard someone who would consider himself a web professional use the term alt tags.

There are no alt tags

Never were.

Anyone involved in web production who refers to image elements’ alternate text attribute as alt tags is a moron.

The basic unit of HTML is an element. A tag is part of an element. An element Starts with an opening tag. This is the angle-bracket stuff, and ends with a closing tag. The element is everything between the opening tag and the closing tag including the tags themselves. Self closing elements don’t have a closing tag and the element is equivalent to the tag.

Note I stated that an element is everything from the < of the opening tag to the > of the closing tag – inclusive. Therefore an element can (and often does) contain other elements. The DTD describe the allowed content for each element. For the purposes of the rest of this rant I will describe elements which require a closing tag as per the HTML 4 DTD. The accompanying image outlines all this in much clearer fashion so I apologise to anyone who cannot view it. Those of you who choose not to view it can just deal.

A representation of the parts of an HTML element

A representation of the parts of an HTML element

The opening tag may contain attributes. An attribute consists of name/value pairs represented as the name, equals sign and value, white space is ignored. In HTML 4 some attributes may be entered as singletons; that is as a name only with the value implied, I don’t consider this good practice but there is no reason not to do it. Attribute values ought to be quoted. This is required in XHTML. In HTML quotes are optional for single word values; this is really bad practice and you ought to quote all attribute values. An image’s alternate text is an attribute. Some attributes are required by certain doctypes, the alternate text attribute of an imgage element being one such required attribute.

There are some restrictions on attribute values but these are often specific to certain attributes. For example the id attribute’s value should not start with a numeric. Some parsers seem to expect some attributes in a particular order. The W3C HTML validator seems to chuck a wobbly if an image element’s opening tag has something other than a source attribute as the first attribute. This is not strictly required.

A (non-self-closing) HTML element usually contains child nodes. These may be other elements or text nodes (which is just text and is usually referred to as text except by weird DOM-nerds). White space only text nodes usually exist within a DOM tree but can be ignored for most cases except when traversing the tree.

Some elements are restricted in what they can contain as child nodes. An unordered list element, for example, may only contain list item elements as its child nodes and (in HTML 4.01) a fieldset element must contain a legend element. There are some general rules of thumb to make this a little clearer (these rules omit the possible existance of whitespace text nodes withing the DOM tree):

  • inline elements must not contain block elements;
  • block elements except the paragraph element (<p></p>) may contain other block elements;
  • ordered and unordered list elements must contain list item elements as their immediate descendents;
  • definition list elements must contain definition term and definition data elements as their immediate descendents;
  • select elements must contain option elements or option group elements as their immediate descendents and option group elements may only contain option elements;
  • uou cannot nest forms (which stuffs up many ASP applications) or textareas;
  • use your common sense!

Mini-note fixes

September 17th, 2008

3D and WPA

A few months ago I blogged early thoughts on my HP Mini-note 2133 and noted a couple of issues. I finally got compiz running. Horrah! And WPA is now much more solid. The big issue was There are a couple of problems with the Laptop Testing Team’s wiki entry. Until I get approval to update the wiki this is what I found:

  • In /usr/bin/compiz adjust the WHITELIST to include via but do not remove the fglrx entry – add via to the WHITELIST. Then compiz works
  • Create /etc/default/wpasupplicant but the only line in it should ENABLE WPA – seems obvious but, well, I feel foolish. So your /etc/default/wpasupplicant file should contain ENABLED=1

The P1i and mobile internet

GPRS was working via bluetooth. Then it wasn’t. Then it was again. And yesterday it wasn’t. However sticking a cable in the side does work – and helps preserve a little bit of battery life which is almost as bad on the P1i as  the mini-note. the P1i makes an effective usb 3g modem. This page helps – the important bit is the initialization string (modified for vodafone): AT+CGDCONT=1,”IP”,”vfinternet.com” and the phone number – the lovely people from vodafone reckon *99# works fine in AU; and it does on the Mac Book Pro; but *99***1# seems to work with Ubuntu. Can’t for the life of me think why that should be the case. The rest was cleanly set up by wvdialconf.

Tulips

September 13th, 2008

tulips

Web design survey 2008

August 3rd, 2008

A list Apart is currently running its annual web design survey. Not just for designers, the survey covers many aspects of working on the web. Go do it.

I took the 2008 ALA survey

Pointless protests?

July 30th, 2008

Today in Amnesty International Australia’s online day of protest against internet repression in China. A wonderfully long name for a silly little gag. Whoop de doo!

Except this is important.

Given that people are imprisoned, tortured or murdered for political activity on an almost daily basis in China is the freedom to do what I am currently doing all that important? Well, how do we know when other (more important?) rights are expunged, violated, swept away etc? Do we rely on Xinhua to tell us?

I was in a cab recently. The taxi driver was interested in what I do for a living and was instantly skeptical about ‘rights’ (mix rights with charity and I am immediately labelled a rabid lefty by most people I meet). My point was simple: how often do you complain about the Government? Daily? Weekly? Never – all politicians are wonderful altruistic models of humanity who do a brilliant job?

The point is, if you don’t like what pollies do you can complain. At worst maybe occasionally you will find yourself being ridiculed on today tonight. You won’t (in Australia) usually find yourself in prison or getting a bullet to the back of the head (we are discussing politicians here – police officers are a different matter).

So express yourself and make all the noise you can. Because you can. Which is a right worth fighting whining for!