I don't see anything obviously wrong with your validator. One thing to
note is that the validator object in web.py hides errors if they
raise. I override this in my apps like so:
class Validator(web.form.Validator):
""" Like web.py validator, but raise on error """
def valid(self, value):
try:
return self.test(value)
except:
if web.config.debug:
raise
return False
Maybe try that, and see if you get an error? You might, for instance,
have an attributeerror with your session access -- hard to debug if
you can't see the error though!
Hope this helps.
Cheers,
Justin
On Nov 4, 6:40 pm, Gaurav Puri <[email protected]> wrote:
> I have this form in which I have three validators,
>
> registrationForm = form.Form(
> form.Textbox('fName'),
> form.Textbox('lName'),
> form.Textbox('userId', form.notnull),
> form.Textbox('email', form.notnull,
> form.regexp(r"....@.*", "must be a valid email
> address")),
> form.Password('password', form.notnull),
> form.Password('confirmPassword'),
> form.Textbox('captcha'),
> validators = [form.Validator("Passwords don't match.",
> lambda i: i.password == i.confirmPassword),
> form.Validator("Captcha is incorrect",
> lambda cp: cp.captcha == session.captcha)]
> )
>
> One which looks for an email (I know its very basic :)), and two more
> form fields that I want to validate.
>
> Issues at hand:
> The current form always shows "Captcha is incorrect" even if the
> passwords are incorrect and the captcha is correct.
>
> Similarly if the email is incorrect and all else is good it shows
> "email must be valid" __and__ "captcha is incorrect"
>
> If I take out the captcha validator then it correctly shows the error
> that the passwords are incorrect.
>
> registrationForm = form.Form(
> form.Textbox('fName'),
> form.Textbox('lName'),
> form.Textbox('userId', form.notnull),
> form.Textbox('email', form.notnull,
> form.regexp(r"....@.*", "must be a valid email
> address")),
> form.Password('password', form.notnull),
> form.Password('confirmPassword'),
> form.Textbox('captcha'),
> validators = [form.Validator("Passwords don't match.",
> lambda i: i.password == i.confirmPassword),
> form.Validator("Captcha is incorrect",
> lambda cp: cp.captcha == session.captcha)]
> )
>
> If all the form fields are correct it correctly gets processed.
>
> I check the form as below
>
> if not form.validates():
> for k in form.inputs:
> if k.note != None:
> errors[k.id] = '%s %s' % (k.id, k.note.lower())
> if len(form.validators) > 0:
> for e in form.validators:
> errors['Error'] = e.msg
> web.header('Content-Type','text/html;charset=utf-8')
> return render.register(form=form, errors=errors,
> session=session)
>
> Any ideas
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.