[mod_python] req.form question

Michael S. Fischer michael at dynamine.net
Thu Oct 2 17:27:26 EST 2003

It didn't; whether the value is an object or a list depends on the form 
submission contents.

 From http://www.python.org/doc/2.2.3/lib/node297.html:

If the submitted form data contains more than one field with the same 
name, the object retrieved by "form[key]" is not a FieldStorage or 
MiniFieldStorage instance but a list of such instances. Similarly, in 
this situation, "form.getvalue(key)" would return a list of strings. If 
you expect this possibility (when your HTML form contains multiple 
fields with the same name), use the isinstance() built-in function to 
determine whether you have a single instance or a list of instances. For 
example, this code concatenates any number of username fields, separated 
by commas:

value = form.getvalue("username", "")
if isinstance(value, list):
     # Multiple username fields specified
     usernames = ",".join(value)
     # Single or no username field specified
     usernames = value


Chuck Lima wrote:

> A point of curiosity.  Please don't hurt me.
> Some time ago, I was able to refer to a form field value in this manner:
> req.form["fieldname"]
> Now, I have to refer to the value in this fashion:
> req.form["fieldname"][0]
> Granted, it's been a while since I've done any new scripting with
> mod_python.  I've searched the mailing list and looked at the docs for
> both v2 and v3 but can't find any reference to a change in the form
> attribute of the request object.
> When did the keys for req.form change to a list?
> Thanks,
> -Chuck
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list