This function takes three arguments: parent is the Element instance under which the
content is to be attached; form is the
FieldStorage instance; and cName is the name of the control to be
displayed.
This function is not designed to
deal with file controls. For the special
logic needed in that case, see Section 4.1.1, “Special considerations for uploading files”.
# - - - s h o w C o n t r o l
def showControl ( parent, form, cName ):
'''Display the value of one form control.
'''
So that we don't have to worry about whether a control
has no values, one value, or multiple values, we'll use
the .getlist() method to return a list of
the values as strings. Then we'll join the elements
of that list together with a comma and a space between
each element to form the displayed string..
cValues = form.getlist ( cName )
display = ', '.join ( cValues )
We're ready to generate XHTML: a div
element containing the string “”.
cName=safe
div = et.SubElement ( parent, 'div' )
div.text = '%s=[%s]' % (cName, display )