Reputation: 3608
This example of a validator with dependencies is provided in the web2py book in the chapter, Forms and validators .
def index():
form = SQLFORM.factory(
Field('username', requires=IS_NOT_EMPTY()),
Field('password', requires=IS_NOT_EMPTY()),
Field('password_again',
requires=IS_EQUAL_TO(request.vars.password)))
if form.process().accepted:
pass # or take some action
return dict(form=form)
The dependency on password_again
is based on the raw input for the password field that is received from the form - request.vars.password
.
What is the cleanest way to add a validator that is based on the validated data from a form, eg form.vars.pasword
?
I am thinking in the instance where the value in the field may be sanitised during the validation process (eg, turned to upper case, stripped of leading whitespace, have a checkdigit appended).
Upvotes: 0
Views: 377