Receiving Data from an HTML File : form « CGI Web « Python Tutorial






<HTML>
<form action="cgi-bin/action.py">
 <paragraph>Enter your first name:</paragraph>
 <input type="text" name="firstname" size="40">
 <paragraph>Enter your last name:</paragraph>
<input type="text" name="lastname" size="40">
 <input type="submit">
 <input type="reset">
</form>
</HTML>

File: action.py

#!c:/Python25/python
import cgi

reshtml = """Content-Type: text/html\n
<html>
 <head><title>Hello</title></head>

 <body>
  <h1>Welcome to a Python script!</h1>
  <paragraph>You are identified as: %s</paragraph>
 </body>
</html>"""

form = cgi.FieldStorage()
lastname = form['lastname'].value
firstname = form['firstname'].value
message = firstname + " " + lastname
print reshtml % message








22.3.form
22.3.1.A Simple Form
22.3.2.Creating Self-Posting CGI Scripts
22.3.3.Static Form Web Page (friends.htm)
22.3.4.Demonstrates get method with an XHTML form
22.3.5.Demonstrates post method with an XHTML form
22.3.6.Demonstrates use of cgi.FieldStorage with an XHTML form
22.3.7.List form data
22.3.8.Login form
22.3.9.Receiving Data from an HTML File