Stanimir Stamenkov <s7an10@netscape.net> wrote:
[color=blue]
> /Stanimir Stamenkov/:[color=green]
>> /Paul Morrow/:
>>[color=darkred]
>>> The author of this technique is relying on these fields to be
>>> passed as an array to the form processor (cgi script or whatever),
>>> but can this behavior truly be relied upon? If so, will the values
>>> always be in the same order as they appear in the form?[/color]
>>
>> Yes, yes. Refer to
>> <http://www.w3.org/TR/html4/interact/forms.html#submit-format> once
>> again.[/color]
>
> I have to correct myself - seems like it is not well specified and
> the behavior is really undefined.[/color]
Sorry, I haven't read the thread very carefully, but it seems to me that
there is a minor confusion here, though basically just in a matter of
principle:
The HTML specifications say how the form field contents are passed as
name=value pairs. There is no "array" concept involved, and if some name
parts are of the form foo[index], then that's fine by HTML rules but
treated just as strings of characters - it is up to the form processor to
intepret them as indexed variables, or whatever. I don't think think
there's any fundamental doubt about these principles.
The same name can be used for different fields, and sometimes needs to be
used. But this may cause some practical problems:
According to the specifications, the order of the fields in form data is
the same as the order of fields in the form (in HTML markup). This is
well defined, not undefined. But on the practical side, it is not wise to
rely on browsers getting this right. Even if they worked OK, such
reliance would create unnecessary connections between the exact markup
and the form processing. Some day someone might reorganize the form
without realizing that the processor needs to be changed too - after all,
he just changed the order of some fields! (Maybe even in a manner which
does not change visual appearance, if CSS is used.)
In the special cases where the same name _needs_ to be used, as for a set
of radio buttons in a group, don't rely on any particular order in the
form data. (And for a radio button group, there will be one name=value
part originating from it anyway.)
When it is clear that the order is insignificant, as for any normal set
of checkboxes, you can use the same name for convenience.
[color=blue]
> The only reliable way I can think
> of is the one proposed by Alan Flavell - using number suffixes in
> the field names.[/color]
And this covers the situation where the order of similarly-name fields
might matter. Of course, the suffixes could be anything that can be
conveniently handled in the processor, not necessarily number-like.
--
Yucca,
http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring:
http://www.cs.tut.fi/~jkorpela/www.html