15: <title>Form Results</title>
16: </head>
17: <body>
18: <h2>Here are the results from your survey</h2>
19: <br />
20: <table border=1>''')
21:
22: print('<tr><th>Name</th><td>',fname, lname, '</td></tr>')
23: print('<tr><th>Age range</th><td>', age, '</td></tr>')
24: print('<tr><th>Hobbies</th><td>')
25: for item in formdata.getlist('hobbies'):
26: print(item)v
27: print('</td></tr>')
28: print('<tr><th>Comments</th><td>', comment, '</td></tr>')
29: print('</table>')
30: print('</body>')
31: print('</html>')
In the script2208.cgi code, lines 5 through 8 use the getfirst() method to retrieve the single-
value form data values: fname, lname, age, and comment. Line 25 uses the getlist()
method to retrieve the multivalue hobbies value from the check box options. Because you don’t know
how many (if any) check boxes were selected, you can use the for statement to iterate through the list
to retrieve whatever is there.
When you submit the form from the script2207.html file, you should see the output from the
script2208.cgi script program, as shown in Figure 22.8.
FIGURE 22.8 The results of the script208.cgi script processing the form data.
After you retrieve the form data in your Python script, you can perform any type of processing on it,
including storing it in a database (see Hour 21). Now you’re well on your way to writing fully