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.