AlterEgo
old web2py blog
Useful Links
List all entries
Book
Interactive Examples
F.A.Q.
Free Applications
Plugins
Recipes
Demo of Admin Interface
Semantic web extension
Some of the information here may be outdated, please check the book instead
Edit page
Title:
Security Code:
Body:
(use
this
wiki markup)
Consider this form: test(): form=FORM(LABEL("Username:",INPUT(_name="user_name", requires=IS_NOT_EMPTY(error_message="test"))), INPUT(_type='submit')) This is the general approach to form validation: if form.accepts(request.vars,session,formname='myform'): #option 1 elif form.errors: #option 2 In option 2 you can: a) rewrite error messages: if form.errors.user_name: form.errors.user_name='oops!' b) copy error messages in a dictionary import copy myerrors=copy.copy(form.errors) c) clear errors so that they are not displayed: form.errors.clear() Moreover ``form.components[0]`` is the LABEL object ``form.components[0].components[0]`` is "Username:" ``form.components[0].components[1]`` is the INPUT object ``form.components[0].components[1].attributes['requires']`` is the ``IS_NOT_EMPTY`` object. Technically you can do: form.components[0].components[1].attributes['requires'].error_message="oops!" but this is not a good idea since it easy to get it wrong.
© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by
web2py
- design derived from a theme by
the earlybird
The content of this book is released under the
Artistic License 2.0
- Modified content cannot be reproduced.