[mod_python] HTML form arrays

Jean-Philippe Barrette-LaPierre jpbarrette at savoirfairelinux.net
Wed Sep 1 17:09:29 EDT 2004


I already sent the question but nobody answered, so I'm sending this question 
again. 

if I have a form like this:


<form action="form/test" method="POST">
	<input type="text" name="customer[test]"/>
	<input type="submit"/>
</form>

and if I have a form.py file like this:

---------------------------------
def test(customer, **kargs):
	print customer
----------------------------------

if I submit the form I obtain this:


----------------------------------------------------------------------
Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in 
HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line 136, 
in handler
    result = util.apply_fs_data(object, req.form, req=req)

  File "/usr/lib/python2.3/site-packages/mod_python/util.py", line 361, in 
apply_fs_data
    return object(**args)

TypeError: test() takes exactly 1 non-keyword argument (0 given)
----------------------------------------------------------------------


If I remove the customer argument, I can see that kargs is this:

{'customer[test]': 'myValue', 'req': <mp_request object at 0x4075fa18>}

We can see that form arrays are not treated as they should. I wrote a function 
that will transform those arguments:

{'customer[test]' : 'myValue1',
  'customer[test2][1] : 'myValue2',
  'customer[test3][1][3] : 'myValue3',
  'test' : 'myValue4'}

into:

{'customer' : {'test' : 'myValue1', 
                       'test2' : {'1' : 'myValue2'}, 
                       'test3' : {'1' : {'3' : 'myValue3'} } },
  'test' : 'myValue4'}

Then those values will be almost ready to be passed to the apply_fs_data 
function and the form function will receive correctly its arguments.

What do you think of this?

--
Jean-Philippe Barrette-LaPierre
Maintener of cURLpp




-- 
Jean-Philippe Barrette-LaPierre
Maintener of curlpp


More information about the Mod_python mailing list