Page 332 -
P. 332
form action
Create an HTML form template
Let’s extend yate.py to support the creation of a HTML form. Take a look
a this simple form, together with the HTML markup used to produce it.
The name of the CGI
script to send the
form’s data to.
<form action="cgi-bin/process-time.py" method="POST">
Enter a timing value:
<input type="Text" name="TimeValue" size=40>
<br />
Click the “Send” <input type="Submit" value="Send">
button to submit the </form>
form’s data to your
web server.
When your user clicks on the Send button, any data in the input area is sent
to the web server as part of the web request.
On your web server, you can access the CGI data using the facilities provided
by the standard library’s cgi module:
import cgi
Get the data sent form = cgi.FieldStorage()
from the form as timing_value = form["TimeValue"].value
part of the web
request. Access the value associated with the “TimeValue” key from
the form’s data.
The cgi module converts the data associated with the web request into a
dictionary-like object that you can then query to extract what you need.
296 Chapter 9