[mod_python] Processing Dynamic Forms

Clodoaldo clodoaldo.pinto.neto at gmail.com
Wed Mar 21 10:27:48 EST 2007


2007/3/21, Scott White <scott.w.white at gmail.com>:
> I have my template & request handler written & working but I appear to only
> be able to declare variables for my post method there are declared in my
> form.
>
> Example template:
> <form
>   <input id="custId"
>
>
> Example handler:
> def post(req, custId
>
>
> However I have n number of custIds in a format: custId_01, 02, etc.
> Therefore I'd like to be able to process all form variables so I can iterate
> through them as there are too many to declare.
>
> How would I handle this?   I looked at the req object but didn't any form
> related variables.

If you had this HTML:

<html><body>
<form action="multifield.py" method="post">
<input name="cust_id" type="text">
<input name="cust_id" type="text">
<input name="cust_id" type="text">
<input name="cust_id" type="text">
<input type="submit" value="Submit">
</form>
</body></html>

You could get all cust_id named fields with this publisher function:

def index(req):
   cust_id = req.form.getlist('cust_id')
   return """\
   <html><body>
   <p>%s</p>
   </body></html>
   """ % ', '.join(cust_id)


Regards,
-- 
Clodoaldo Pinto Neto


More information about the Mod_python mailing list