I have to create a HTML form and get the data using python-cgi. HTML form requires user to submit firstname and lastname and then the python script is supposed to get the data generated in the form. I have read up tutorials and tried playing with it to make it work, but it does not seem to happen. HTML code:
<form method = "POST" action ="http://localhost/cgi-bin/pyfile_test.py">
<p>First Name: <input type="text" name="firstname">
<p>Last Name: <input type="text" name="lastname">
<p>Click here to submit the form:<input type="submit" value="Submit">
<input type="hidden" name="session" value="1898fd">
</form>
python script to extract data
#!c:/Python26/python.exe -u
import cgi, cgitb
cgitb.enable()
def main()
print "Content-type: text/html\n"
print
form = cgi.FieldStorage()
if form.has_key("firstname") amd form["firstname"].value !="":
print "<h1>Hello", form["firstname"].value, "</h1>"
else:
print "<h1> Error!Wrong!</h1>
main()
when i direct html form to above script it does NOT work but when i direct it to the following script it works.
#!c:/Python26/python.exe -u
import cgi, cgitb
cgitb.enable()
print "Content-type: text/html"
print
print "The First Python Script On Server Side"
print "The sum of two numbers evaluation"
print "3+5 = ",3+5
I dont know what is going wrong. Any help will be highly appreciated!