26 Apr 2012
School
Department
Course
Professor

CMPT165 Final Exam Review Example-Phone Book Form
directory.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<h1>Virtual Phone Book</h1>
<form action ="phoneBook.py">
<p>Name: <input type:"text" name="name"></p>
<p>Phone #: <input type:"text" name="number"></p>
<p>Type of Phone:</p>
<p><input type="radio" name="type" value="Cell"></p>
<p><input type="radio" name="type" value="Work"></p>
<p><input type="radio" name="type" value="Landline"></p>
<p><input type="submit" value="Add!"></p>
</form>
</body>
</html>
phoneBook.py
from file import*
import cgi
form = cgi.FieldStorage()
print "Content-type: text/html"
print
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">"""
print "<html>"
print "<head>"
print "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">"
print "<title></title>"
print "</head>"
print "<body>"
name = form["name"].value
phone# = form["phone#"].value
phoneType = form["type"].value
newPhone = [phone#, phoneType]
phoneList = [newPhone]
newPhoneProfile = [name, phoneList]