[mod_python] strange behavior of form + patch for mod_python

Jim Gallacher jpg at jgassociates.ca
Sat Nov 26 14:06:10 EST 2005


Deron Meranda wrote:
> On 11/26/05, Rafal Zawadzki <bluszcz at jabberpl.org> wrote:
> 
>>When i set one checkbox, form['testkey'] result is key. When I set two or
>>more, this is a list. IMVHO it is a BIG bug.
> 
> 
> When the submitted form is being processed there is no way for it to
> know how the form variables were created, whether by checkboxes, or
> whatever.  So unless it sees a particular named variable more than
> once, there is no way to anticipate you want a list rather than a
> single value.  For most other input types other than checkboxes you
> will almost always want a single value anyway, and not a list.
> 
> Also there is a lot of prior tradition that this is how python HTML
> form processors should work.  For instance the standard cgi module
> also does it this way.
> 
> What you can/should do instead is to just change it to a list in your
> template if you want rather than patching mod_python.  You can easily
> write a helper function as so:
> 
>   def force_as_list( v ):
>      if type(v) is not type([]):
>         return [v]
>      return v


Or use form.getlist('testkey')

;)

Jim



More information about the Mod_python mailing list