I am trying to understand how to pass data back and forth from a form to a
python script. I mostly have it working now, but I am unsure about how to
find out which variables are being passed from the html. I can see them in
the form.list, but I need to iterate over them and print a label for each.
Currently the data gets printed out like this:

[MiniFieldStorage('fname', 'Vicki'), MiniFieldStorage('lname',
'Stanfield'), MiniFieldStorage('addr', '123 Street'),
MiniFieldStorage('pwd', 'sdkfsadf'), MiniFieldStorage('prod[]', 'Cases'),
MiniFieldStorage('email', 'on'), MiniFieldStorage('buyDays', '10')]

I need something more like this:

First Name: Vicki
Last Name: Stanfield
etc.....

The code I have so far is this:

#! /usr/bin/python
import cgitb, os, sys
cgitb.enable()
sys.strerr = sys.stdout

import cgi

print "Content-Type: text/html\n\n"
print
print "<html><head></head><body>\n\n"

form = cgi.FieldStorage()
if ( os.environ['REQUEST_METHOD'] == 'POST' ):
     if form.list != []:
        print form.list
     else:
        print "No POST data."
elif ( os.environ['REQUEST_METHOD'] == 'GET' ):
    if form.list != []:
        print form.list
    else:
        print "No GET data."
print "</body></html>\n\n"
---------------------------


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to