= A more complex example = Here is a rather more complex example that uses a number of different input types. Here's the model. {{{#!python class User: def __init__(self): self.name = '' self.an_int = 0 self.a_float = 0.0 self.country = 0 self.password = '' self.active = False }}} The form that describes how we want it laid out {{{#!python # Slightly abridged list of all the countries in the world. country_names = ( 'Australia', 'Belgium', 'Cuba', 'Greenland', 'Madagascar', 'Netherlands', 'Switzerland', 'Uzbekistan', 'Zimbabwe' ) country_menu = [e for e in enumerate(country_names)] fields = ( TextField('Name', 'name', required=True), IntegerField('Integer', 'an_int'), FloatField('Float', 'a_float'), SelectField('Country', country_menu, 'country'), PasswordField('Password', 'password', required=True), Checkbox('Active', 'active'), ) buttons = Buttons(( Button('Save', 'save'), Button('Cancel', 'cancel'), )) fieldsets = (Fieldset(fields), ) ctx.locals.test_form = FieldsetForm('User details', fieldsets, buttons=buttons) }}} Render the form on the page: {{{#!html
}}} That looks like this: {{attachment:forms-complex-1.png}} To render the form as static report: {{{#!html
}}} In the {{{forms.py}}} file, the code looks like: {{{#!python def page_enter(ctx): if not ctx.has_value('test_form'): ctx.locals.description = User() ctx.add_session_vars('description') ctx.locals.test_form = [see above] def page_display(ctx): ctx.run_template('forms.html') def page_process(ctx): if ctx.req_equals('save'): try: ctx.locals.test_form.validate() except FormValidationError, e: ctx.locals.test_form.set_disabled(False) return ctx.locals.test_form.set_disabled(True) # This disables the FieldSet! # update the values in the model from the form ctx.locals.test_form.merge(ctx.locals.description) # now you can do things with the updated object, eg ctx.log('user %s, active %s' % (ctx.locals.description.user, ctx.locals.description.active)) elif ctx.req_equals('reset'): ctx.locals.test_form.clear() ctx.locals.test_form.set_disabled(False) elif ctx.req_equals('cancel'): if ctx.locals.test_form.disabled: ctx.locals.test_form.set_disabled(False) else: ctx.locals.test_form.clear() ctx.redirect('main') }}}