Here is an example of a working CGI script, anyform.cgi. It is intended to display all the
data from an arbitrary form. The example form in Section 3.1, “Linking a form to a CGI script” uses this script as its handler.
First let's look at the HTML we want to generate.
Suppose a form has two controls: a text field
named 'home' containing the string
'Eagles', and a multiple select
menu named 'visitors' with two values:
'Animal Angst Project' and 'Bovine
Wonder Horde'.
For simplicity, we'll use the .getlist()
method on the FieldStorage instance to get
any number of values for each control. Then we'll
concatenate the values inside square brackets, with
commas between them. Here's the output:
<html>
<head>
<title>Form output test</title>
</head>
<body>
<h1>Form output test</h1>
<div>home=[Eagles]</div>
<div>visitor=[Animal Angst Project, Bovine Wonder Horde]</div>
</body>
</html>