Help with CGI

lost lost at soul.net
Sun Apr 13 15:41:45 EDT 2003


Hi there, 
I'm trying to write a program which prints the html page, and when form
data has been submitted, it prints the html again, but with the keys and
values from the form.
here's the code i have so far:(bottom of post)

I can't get the "for key in form.keys():" part to run....
I'd also like to ONLY print the html if there are no values in the cgi, so
I'd need something like:
if form.keys == [""]: #if there are no keys submitted
	do this...

any help for what I need to do? 
cheers!


#!/usr/bin/python
print "Content-type: text/html\n\n"                                                                                                                                  
#get cgi data into a list...
import cgi
form = cgi.FieldStorage
                                                                                                                                   
print """
<html>
<head><title>Hello</title></head>
<body>
<form name=\"login_form\" method=\"post\" action=\"http://pertelotte/cgi-bin/test.py\">
<table width=\"85%\" align=\"right\" border=\"1\">
        <tr>
                <td width=\"40%\" align=\"right\"><font size=\"-2\">Enter your details:</font></td>
                <td align=\"right\"><font size=\"-2\">Username: </font><input type=\"text\" name=\"uname\" size=\"15\"></td>
                                                                                                                                   
                <td align=\"right\"><font size=\"-2\">Password: </font><input type=\"password\" name=\"pword\" size=\"15\"></td>
                <td colspan=\"2\" align=\"right\">
                <input type=\"submit\" name=\"submit\" value=\"Login\">
                </td>
        </tr>
</table>
</form>
<br><br>
<hr width=\"100%\">
"""
for key in form.keys():
        print key
                                                                                                                                   
print """
</body>
</html>
"""





More information about the Python-list mailing list