[Tutor] cgi module and checkboxes.

Magnus Lycka magnus@thinkware.se
Thu Dec 12 09:25:02 2002


At 00:25 2002-12-13 +1300, Thomi Richards wrote:
>unfortunately, i still cannot get my head around it. surely the uid vale
>in the FieldStorage thingy what should be something like the following:
>
>print form['uid'].value
>['1','4','6']
>
>which would mean that the user clicked on the 1st, 4th and 6th check
>boxes? (remember that the value parameter on the check boxes is set to
>user ID numbers, which are a unique number within the system).

Why guess when you have both the possibility to experiment and
good docs? Have you tried something obvious like???

#!/usr/bin/python -u
print "Content-type: text/html"
print
print "<pre>"
import cgi
form = cgi.FieldStorage()
print form
print "</pre>"

That should give you some hint about what is happening.

Then you could read

http://www.python.org/doc/current/lib/node298.html

Note getlist() !!!

Perhaps "print form.getlist('uid')" is what you want?

And by all means: Use cgitb!
http://www.python.org/doc/current/lib/module-cgitb.html

So, you might end up with something like

#!/usr/bin/python -u
import cgi, cgitb
cgitb.enable()
form = cgi.FieldStorage()
print "Content-type: text/html"
print
print "<pre>"
print form.getlist('uid')
print "</pre>"


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se