Nicolas Lehuen wrote:
According to the W3C, "The control names/values are listed in the
order they appear in the document."

http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1

Which also says to "Please consult [RFC2388] for additional information." without actually saying that it contradicts or supercedes 2388. It's usually at this point I want to run off an set my hair on fire.

But that doesn't say anything about the server side...

And both specs are strangely silent on the whole issue of building a hash table from the form data and providing a list of the names used as keys in creating that table. ;)

This part of the discussion really only affects the FieldStorage.keys() method. The mod_python documentation states "The FieldStorage class has a mapping object interface i.e. it can be treated like a dictionary", with no mention of any special ordering behaviour for the keys. It seems to me users would be foolish to expect anything other the standard python dict behaviour. We should be free to return any order we want from keys().

Relying on the field order is a mark of sloppy programming IMHO.But
maybe there are corner cases when handling a series of checkboxes with
the same name is easier if the values are given in the order they were
found in the form.

Ahh... but the values *would* be returned in the correct order for a given key, since internally the index dictionary values are stored as a list of fields. Consider this possible code snippet for use in __init__().

        self.list.append(field)
        if key in self.index:
            self.index[key].append(field)
        else:
            self.index[key] = [field,]

Order is preserved for a particular field name, so we are still sloppy-coder friendly. :)

Jim


Regards,
Nicolas

2005/11/28, Jim Gallacher <[EMAIL PROTECTED]>:

Gregory (Grisha) Trubetskoy wrote:

On Mon, 28 Nov 2005, Nicolas Lehuen wrote:


Why is the ordering so important ? I do understand we need to support
multiple values per field name, but I don't see why ordering is
needed.


I think that it may be dictated by some RFC (the stdlib does it this way
too), I'm not sure, but it's a good question though, it'd be great to
have it researched and answered so that we don't have to go over this
point again.

Grisha



Ordering is not defined according to my interpretation. But at the same
time we shouldn't mess with the ordering. Gotta love those RFCs. :)

http://www.ietf.org/rfc/rfc2388.txt?number=2388

Returning Values from Forms:  multipart/form-data

5.5 Ordered fields and duplicated field names

   The relationship of the ordering of fields within a form and the
   ordering of returned values within "multipart/form-data" is not
   defined by this specification, nor is the handling of the case where
   a form has multiple fields with the same name. While HTML-based forms
   may send back results in the order received, and intermediaries
   should not reorder the results, there are some systems which might
   not define a natural order for form fields.

Jim




Reply via email to