Form Elements

T
he FORM container creates an HTML form. Its action is hard-coded to POST, and its encoding type (enctype) is hard-coded as multipart/form-data. If you find either of these hard-codings problematic, re-examine your motivations: the structure of URLs on this site means a form submitted with GET has its contents thrown into internal--not an appropriate place for user-generated data.

The FORM constructor takes a keyword argument, action=. If this argument is a string, it is used as the action attribute of the <form> tag. If it is a Display object, then the form will submit to the action URL for that object.

There are several Output subclasses representing form controls. All but one are subclasses of INPUT, the constructor for which takes a single argument, the attrs dictionary. The dictionary specifies the attributes of the generated tag. So, for instance, the tag <input type="text" name="foo" value="bar"> would be represented as TEXT_INPUT(attrs={'name' : 'foo', 'value' : 'bar'}). The subclasses are:

  • TEXT_INPUT
  • SUBMIT_INPUT
  • RESET_INPUT
  • RADIO_INPUT
  • PASSWORD_INPUT
  • IMAGE_INPUT
  • HIDDEN_INPUT
  • FILE_INPUT
  • CHECKBOX_INPUT
  • BUTTON_INPUT

Finally, the SELECT class creates <select> tags within a form. Its constructor takes the following keyword arguments:

name
The name attribute of the control.
options
A list of pairs (n, k) where n is the name (seen by the user) and k is the key (seen by the program).
default
The key or list of keys which should be selected initially.
size
The number of rows in a multiple select control.
multi
Boolean: true means this is a
otherwise it's a
attrs
Any additional attributes for the <select> tag.