Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 5 and Version 6 of FormValidationWithWidgetsTwo


Ignore:
Timestamp:
01/31/07 11:01:19 (12 years ago)
Author:
jorge.vargas
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FormValidationWithWidgetsTwo

    v5 v6  
    1 == Form Validation with FormEncode Schema == 
    2  
    3 This example uses a FormEncode schema along with a TableForm widget to validate password fields.  The password fields must match or the form is redisplayed with an error message.  I just modified the quickstart controllers.py file.  To keep it simple, I'll not include the root controller in the example. 
    4  
    5 I wrote this with SVN revision 770. 
    6  
    71{{{ 
    8 #!python 
    9 import cherrypy 
    10 import turbogears 
    11 from turbogears import controllers 
    12 from turbogears import identity 
    13 from turbogears import widgets 
    14 from turbogears import validators 
    15  
    16 class MySchema(validators.Schema): 
    17     pwd1 = validators.String() 
    18     pwd2 = validators.String() 
    19     chained_validators = [validators.FieldsMatch('pwd1', 'pwd2'), ] 
    20  
    21 def createPasswordForm(controller=None): 
    22     field1 = widgets.PasswordField('pwd1') 
    23     field2 = widgets.PasswordField('pwd2') 
    24     form = widgets.TableForm(fields=[field1, field2], name='myform', 
    25                              validator=MySchema()) 
    26     return form 
    27  
    28 class FormTest(controllers.Controller): 
    29     @turbogears.expose(template="turbogears.fastdata.templates.form") 
    30     def index(self): 
    31         return dict(obj=None, action='test', form=createPasswordForm()) 
    32  
    33     @turbogears.expose() 
    34     @turbogears.validate(form=createPasswordForm) 
    35     @turbogears.error_handler(index) 
    36     def test(self, pwd1, pwd2): 
    37         return "Password1: %s<br />Password2: %s" % (pwd1, pwd2) 
     2#!NewsFlash 
     3This wiki page has been migrated to the new docs site currently at  
     4http://docs.turbogears.org/1.0/RoughDocs/FormValidationWithSchemas 
    385}}} 
    39  
    40 In your template, add: 
    41  
    42 {{{ 
    43 form.display(obj, action=action) 
    44 }}} 
    45  
    46 Now you only have to add this line to your root controller as a class attribute 
    47 {{{ 
    48 #!python 
    49 formtest = FormTest() 
    50 }}} 
    51 and visit the url [http://localhost:8080/formtest/].