#from FormKit import Form, BaseChoiceClasses, Validators, Fields ## extends SitePage ##-------------------------------------------------------------------------- #def awake <%# ### Setup form widgets ### # Only do this the first time through if not hasattr(self, 'form'): self.form = Form.Form() subjects = [ ('Math', 1), ('English', 2), ('History', 3), ] notEmpty = Validators.NotEmpty() # Name Field self.form.addField( Fields.TextField( 'name', validators=[notEmpty] ) ) # Subject Pulldown self.subjectSelectField = Fields.SelectField('subject') self.form.addField( self.subjectSelectField ) for name, id in subjects: self.subjectSelectField.addChoice( id, name ) # Submit Button self.submitButton = Fields.WebKitSubmitButton(name="submit", label="Submit") self.form.addField( self.submitButton ) %> #end def ##----------------------------------------------------------------------- #def theForm
Name: <%= self.form.name.tag() %>
Subject: <%= self.form.subject.tag() %>
<%= self.form.submit.tag() %>
#end def ##----------------------------------------------------------------------- #def successMessage
Thanks for entering.
name: "<%= self.form.name.value() %>"
subject: <%= self.form.subject.value() %>
#end def ##-------------------------------------------------------------------------- #def processForm #end def FormKit with Cheetah Example

FormKit with Cheetah Example

<% # clear any values from last form processed self.form.reset() self.form.process( trans.request().fields() ) # Three possible conditions: (1) new form, (2) submitted form with errors, (3) success if '_action_submit' not in trans.request().fields(): # New form trans.response().write( self.theForm() ) elif not self.form.isSuccessful(): # submitted but has errors message = '
Please fix these fields:
%s
' % '\n
'.join( self.form.errors() ) trans.response().write( message ) trans.response().write( self.theForm() ) else: # Success trans.response().write( self.successMessage() ) %>