LetterType.cgi
Example of a simple "typing" interface using CGI. Two variables are used for state, one to represent the "current word", and a second to represent the "current letter" to be typed.
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
fs = cgi.FieldStorage()
curword = fs.getvalue("curword", "")
addletter = fs.getvalue("addletter", None)
if addletter:
curword += addletter
print "Content-type: text/html; charset=utf8"
print
print "<html><head><title>lettertype</title></head><body>"
letters = "abcdefghijklmnopqrstuvwxyz"
print "<p>"
for l in letters:
print """<a href="?curword=%s&addletter=%s">%s</a>""" % (curword, l, l)
print """<a href="?">clear</a>"""
print "</p>"
print "<h2>%s</h2>" % curword
print """
</body>
</html>
"""
Note how the "clear" links works by clearing all state.
Exercise
Implement a "backspace" link.