Click here to get back home

spaces (and worse) in names ?

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
spaces (and worse) in names ? Chris Sharman 02-01-2006
Get Chitika Premium
Posted by Chris Sharman on February 1, 2006, 9:00 am
Please log in for more thread options


Are spaces allowed in names ?
Eg <input name="my field" type="text" value="my data">

The html4 dtd seems to say this is cdata, which allows embedded single
spaces, but say agents may trim leading & trailing space, and should
replace any whitespace character(s) with a single space.

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.

So are spaces permitted, or not, and more to the point how universally
do they work ?

(they work for me in fx1.5 and ie6/w2k)
they even work on the vms/osu webserver, which uppercases everything!

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.

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"...> ?

Posted by mbstevens on February 1, 2006, 9:39 am
Please log in for more thread options


Chris Sharman wrote:

> 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.

To be on the safe side, you can
use regular expressions to alter the data as it arrives. I'd
strip the leading and trailing spaces and punctuation, and
substitute underlines for internal spaces in the actual field names.

With another regular expression, you can sub spaces for
underlines for printable labels and the like.

Perl, PHP, Python, and Ruby all have easy access to regular
expressions. Friedel's "Mastering Regular Expressions" is
a good book to have in your library. It's like learning a small
extra language, but it's really necessary for a lot of website
tasks.
--
mbstevens
http://www.mbstevens.com/




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

Similar ThreadsPosted
Spaces in directory names -- ugly!! July 31, 2004, 1:25 pm
worse websites... August 16, 2005, 1:30 am
Document name (with spaces) in URL July 22, 2004, 6:17 pm
Images and spaces December 31, 2007, 11:33 am
mailto: form using GET. Cannot get spaces in text. March 29, 2007, 6:16 am
How to remove spaces inside the cell January 10, 2008, 8:42 am
two images in one row with proper spaces and without tables September 5, 2008, 7:46 pm
Domain names and XML January 28, 2005, 7:45 pm
Re file names and IE October 15, 2005, 1:28 am
HTML - CSS variable names correspondence. March 28, 2005, 9:14 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap