CGI multiple select?
Gerhard Häring
gh_pythonlist at gmx.de
Mon Apr 8 17:59:01 EDT 2002
* John <nobody at nobody.com> [2002-04-08 15:35 -0500]:
Do you own the nobody.com domain? If not, you're abusing their services.
If I were the domain owner, you'd get into trouble. If all you want is
not receive spam, please get yourself a throway account at a freemailer
instead.
> Hi,
>
> In my html form, I have 'multiple select'
>
> <select name=spred multiple>
> <option..>
> <option..>
>
> This form invokes CGI routine, where I try to read selected entries from
> form["spred"]
>
> My dilemma is here:
>
> When only one entry is selected:
> form["spred"].value (will be the object selected)
>
> When multiple entries were selected:
> for o in form["spred"]:
> o.value (--> each of these will be the object selected)
Dunno. This works fine for me and it gets lists only - a one-element
list for one choice and an empty list if nothing is selected:
#!/usr/local/bin/python
import cgi
try:
import cgitb
cgitb.enable()
except ImportError:
pass
# URL of this cgi script
MYURL = "/cgi-bin/test.py"
print "Content-type: text/html\n\n"
form = cgi.FormContentDict()
optionen = form.get("cities", [])
print """
<html>
<body>
<p>
<b>You selected these entries last time:</b>
%(optionen)s
</p>
<form action="%(myurl)s">
<select name="cities" multiple>
<option>Paris</option>
<option>Moscow</option>
</select>
<input type="submit>
</form>
</body>
</html>""" % {"myurl": MYURL, "optionen": optionen}
Gerhard
--
This sig powered by Python!
Außentemperatur in München: 6.6 °C Wind: 0.7 m/s
More information about the Python-list
mailing list