Ah that makes a lot more sense, I should not code tired. I also tried out IS_EQUAL_TO() and works like a charm. Thanks.
On Jun 27, 3:31 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > IS_EXPR('value==repr(request.vars.password)', > > should be > > IS_EXPR('value==%s' % repr(request.vars.password), > > Anyway, this seems to come up a lot, so I added a new validator in > trunk: > > IS_EQUAL_TO(request.vars.password) > > Please give it a try. > > On Jun 27, 1:52 am, Alastair Medford <alastairmedf...@gmail.com> > wrote: > > > Alright, I'm burned out on trying to solve this. > > > I'm trying to make a form that checks if two fields match, like > > password + verify password. I noticed in the book that there's an > > example of this, but I can't seem to get it working. The code given is > > as follows (this is with a typo correction, a quote is missing in > > IS_EXPR in the book): > > > def index(): > > match_it = IS_EXPR('value==repr(request.vars.password)', > > error_message='passwords do not match') > > form = SQLFORM.factory( > > Field('username', requires=IS_NOT_EMPTY()), > > Field('password', requires=IS_NOT_EMPTY()), > > Field('password_again', requires=match_it)) > > if form.accepts(request.vars, session): > > pass # or take some action > > return dict(form=form) > > > I run this code exactly, and while it works for displaying the page, > > as soon as I submit the form I get the following error: > > > Traceback (most recent call last): > > File "gluon/restricted.py", line 178, in restricted > > File "E:/development/web2py/applications/informed/controllers/ > > users.py", line 23, in <module> > > File "gluon/globals.py", line 96, in <lambda> > > File "E:/development/web2py/applications/informed/controllers/ > > users.py", line 11, in index > > File "gluon/sqlhtml.py", line 857, in accepts > > File "gluon/html.py", line 1311, in accepts > > File "gluon/html.py", line 454, in _traverse > > File "gluon/html.py", line 454, in _traverse > > File "gluon/html.py", line 454, in _traverse > > File "gluon/html.py", line 454, in _traverse > > File "gluon/html.py", line 461, in _traverse > > File "gluon/html.py", line 1118, in _validate > > File "gluon/validators.py", line 156, in __call__ > > File "<string>", line 1, in <module> > > NameError: name 'request' is not defined > > > Now I imagine this is happening because the IS_EXPR code doesn't have > > access to the request global. If this is the case, then how can I > > achieve the result I'm looking for, and why is this example in the > > book?