[mod_python] Newbie needs help with forms

dannoritzer at web.de dannoritzer at web.de
Sat Feb 14 09:33:44 EST 2004


Jim,

I have to admit, I haven't used the FieldStorage class explicitly yet.

The way I access the form data is using the form attribute from the 
Request object.

See the documentation at: 
http://www.modpython.org/live/current/doc-html/node85.html


Try doing it like this:

(snip)
          for i in req.form.keys():
                  html_page.append(i)
(snip)


Guenter





Jim wrote:

> I am new to modpython and I could use a hand with forms. I currently
> have the publisher setup. The following snippit of code prints none of
> the form vars that I (thought) I was passing. When I click submit test
> gets loaded but the page is blank. I thought iterating through the keys
> would work. What am I doing wrong here? 
> 
> TIA - Jim
> 
> from mod_python import apache, util
> import HTMLgen
> from HTMLgen import *
> 
> def test(req):
>         html_page = HTMLgen.BasicDocument(title='Test')
>         for i in util.FieldStorage(req).keys():
>                 html_page.append(i)
>         return html_page
>                                                 
> def handler(req):
>         html_page = HTMLgen.BasicDocument(title='Register')
>         f = Form('http://69.56.173.110/register.py/test')
>         f.append("Please pick a username and password")
>         f.append("Username")
>         f.append(Input(type='textfield', name='username'))
>         f.append("Password")
>         f.append(Input(type='password', name='passwd'))
>         f = space(f)
>         role = ['Official', 'Coach', 'Parent', 'Player']
>         for choice in role:
>                 r = Input(type='radio', name='role', rlabel=choice)
>                 f.append(r)
>         f.submit = Input(type='submit', value='register')
>         html_page.append(f)
>         req.write(str(html_page))
>         return req
> 
> 
> _______________________________________________
> 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