I just do

FORM(INPUT(_name='pass1'),INPUT(_name='pass2', requires=IS_EXPR
('value==%s' % repr(request.vars.pass1)),INPUT(_type='submit'))


On Apr 7, 6:37 pm, waTR <roman.goldm...@gmail.com> wrote:
> I am looking to write a validator that takes as its arguments a
> request.post_vars.pass1 and request.post_vars.pass2. This is to check
> if when the use enters a password in 2 fields that they are the same.
>
> It then checks if they match, and if they don't it flashes an error
> saying passwords do not match.
>
> In addition, two questions:
> 1. Where should I store this custom validator?
> 2. How do I import this custom validator to use in my controller?
>
> Here is the code I have so far:
>
> from storage import Storage
> from gluon.utils import md5_hash
>
> class IS_PASS_MATCH(object):
>     """
>         example:
>         INPUT(_type='text',_name='pass1',requires=IS_NOT_EMPTY())
>         INPUT(_type='text',_name='pass2',requires=IS_PASS_MATCH
> (request.post_vars.pass1, request.post_vars.pass2))
>     """
>
>     def __init__(self, passwd1, passwd2, error_message='Passwords do
> not match!'):
>         self.error_message = error_message
>         self.pass1 = passwd1
>         self.pass2 = passwd2
>
>     def __call__(self, value):
>         try:
>             if(self.pass1 == self.pass2):
>                 return(value, None)
>             else:
>                 return (value, self.error_message)
>         except:
>             return (value, self.error_message)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to