|
Posted by Jukka K. Korpela on February 1, 2006, 10:12 am
Please log in for more thread options
Chris Sharman wrote:
> Are spaces allowed in names ?
> Eg <input name="my field" type="text" value="my data">
Yes, spaces are allowed in those attribute values.
> The html4 dtd seems to say this is cdata,
> Right.
> which allows embedded single spaces,
It allows any number of spaces; value="", value=" "
and value=" " are all OK.
> but say agents may trim leading & trailing space, and should
> replace any whitespace character(s) with a single space.
That's an obscure point and hardly what the spec writers _meant_ in
general. Surely alt="" should be treated as distinct from alt=" ".
Surely value="foo" and value=" foo " in an <input> element should be
treated differently. I would be surprised if browsers behaved
differently. But this seldom matters in practice; we hardly need to rely
on preservation of leading or trailing spaces.
> It then goes on to give further constraints "not expressed by the DTD",
> restricting id & name to a letter, followed by alphanumerics, hyphen,
> underscore, colon and/or period.
No, the id attribute is constrained by the DTD as being of type ID,
whereas the name attribute has different rules for different elements.
In <a name="...">, rules are quite different from <input name="...">.
> The reason I ask is that I have a database driven application with
> generated field names, containing spaces, possibly some punctuation, and
> maybe even accented characters eventually, and I'm wondering how to
> handle it.
I wouldn't worry about spaces or punctuation. Non-ASCII characters are a
different matter, and you need to consider how they can be transmitted.
> Talking of which - how should I handle multi-national input on a web
> form (accented names etc) ? Is it <form accept-charset="ISO-8859-1"...> ?
The accept-charset attribute is probably ignored by all browsers. What
matters in practice is the encoding of the _page_ containing the form.
As usual, I recommend Alan Flavell's "tutorialish notes" on this:
http://ppewww.ph.gla.ac.uk/~flavell/charset/form-i18n.html
|