Hi Franki

Uou asked 

"Firstly I have a need to check that two password fields on a page match:
password and password2"

I just asked the question about matching passwords last week on the
Data::FormValidator list (Thanks, Mark, for the solution). I also needed
other things that you were interested in:

* Passwords must be 6 chaacters or more
* Some custom messages

I don't know if I wrote thinks the best way - a regex for password length
woulkd have been better - but here's what I came up with:

    ... Main code
    my ( $results, $err_page ) = $self->check_rm('user_form',
'_user_profile');
    return $err_page if $err_page;
    ... Main code continues

sub _user_profile{
    return {
        required => [qw(username password1 password2 first_name last_name
                     role_id acst_id site_id function)],
        optional => [qw(user_id)],
        constraints => {
            password1 => {
                name => 'invalid_password1',
                constraint => \&_check_pass,
                params => ['password1']
            },
            password2 => {
                name => 'invalid_password2',
                constraint => \&_check_pass,
                params => ['password2']
            },
            password1 => {
                name => 'confirm',
                constraint => sub {
                    my $password1 = shift;
                    my $password2 = shift;
                    return ($password1 eq $password2);
                },
                params => [qw(password1 password2)]
            },
        },
        msgs => {
            any_errors => 'some_errors',
            prefix => 'err_',
            constraints => {
                "confirm" => "Passwords don't match",
                "invalid_password1" => 'Password is invalid',
                "invalid_password2" => 'Password is invalid''
            },
        }
    }
}

sub _check_pass{
    my $password = shift;
    return 0 unless (length($password) >= 6);
    return 1;
}
           


 

-----Original Message-----
From: Franki [mailto:[EMAIL PROTECTED] 
Sent: Monday, 11 October 2004 9:44 p.m.
To: [EMAIL PROTECTED]
Subject: [cgiapp] ValidateRM


Hi guys,

Firstly let me apologise for asking this if it is a stupid question. :-)

I've only recently started trying to use the validateRM in conjunction 
with cgi:app and I must say I am impressed.
I've not had any experience with the validation frameworks before, so 
some aspects are very confusing to me.
(as an added problem, I'm not a guru like a good many on this list 
appear to be.)

Anyway, I have a couple of little questions I'd like to ask you.

Firstly I have a need to check that two password fields on a page match: 
password and password2. (to ensure they entered it properly), can I use 
validate to do this or must it be coded separately?
Normally I would match them manually, and return if they don't match 
with my homegrown messaging system, but if I can do that with validateRM 
it would make sense to do so.
 From the look of it, I could do the match manually and put any error 
into  the $err_page object to return the message, it is that the best 
way to do it?

One thing thing that I couldn't find in Marks example code is a way to 
pass custom error messages on a per field basis. right now I am getting 
basic "invalid" or "missing" errors.

Below is the very basic code I have working thus far. (I've not tweaked 
the regex beyond anything very basic at this stage.)
I'd like to be able to pass error messages like: (for username) "must be 
at least 8 characters"
and if the passwords don't match: "Your passwords don't match" And so on for
the other fields.

I thought putting:
err_username   => 'Username must be over 6 characters',
Into the "msgs" hash would force that message, but it doesn't appear to 
be working, I still get the "Invalid" message.

Can anyone give me pointers in this regard?

many thanks

Rgds

Franki

          my ($results,$err_page) = $self->check_rm('start_window', {
                         required => [qw/
                                        username
                                        password
                                        password2
                                        muncipality_name
                                        muncipality_number
                                        muncipality_street
                                        muncipality_city
                                        muncipality_state
                                        muncipality_zip
                                        muncipality_auth_officer
                                        muncipality_phone
                                     /],
                         optional => [qw/
                                        muncipality_fax
                                        muncipality_email
                                     /],
                         constraints => {
                                # required params
                                username                => '/\w{4}/',
                                password                => '/\w{6}/',
                                password2               => '/\w{6}/',
                                muncipality_name        => '/\w{2}/',
                                muncipality_number      => '/\w{1}/',
                                muncipality_street      => '/\w{3}/',
                                muncipality_city        => '/\w{3}/',
                                muncipality_state       => '/\w{2}/',
                                muncipality_zip         => '/\d{3}/',
                                muncipality_auth_officer=> '/\w{3}/',
                                muncipality_phone       => '/\d{6}/',
                                # optional params
                                muncipality_fax         => '/\d{6}/', # 
make sure the fax  is over 6 digits.
                                muncipality_email       => '/\w{5}/', # 
make sure the email is valid.
                                        
},                                    
                        # trim leading and trailing whitespace from all 
the valid fields.
                        filters         => ['trim'],
                        msgs=>{
                                any_errors => 'err__',
                                prefix     =>'err_',
                        },         
          });


Dan


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[EMAIL PROTECTED]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-----Original Message-----
From: Franki [mailto:[EMAIL PROTECTED] 
Sent: Monday, 11 October 2004 9:44 p.m.
To: [EMAIL PROTECTED]
Subject: [cgiapp] ValidateRM


Hi guys,

Firstly let me apologise for asking this if it is a stupid question. :-)

I've only recently started trying to use the validateRM in conjunction 
with cgi:app and I must say I am impressed.
I've not had any experience with the validation frameworks before, so 
some aspects are very confusing to me.
(as an added problem, I'm not a guru like a good many on this list 
appear to be.)

Anyway, I have a couple of little questions I'd like to ask you.

Firstly I have a need to check that two password fields on a page match: 
password and password2. (to ensure they entered it properly), can I use 
validate to do this or must it be coded separately?
Normally I would match them manually, and return if they don't match 
with my homegrown messaging system, but if I can do that with validateRM 
it would make sense to do so.
 From the look of it, I could do the match manually and put any error 
into  the $err_page object to return the message, it is that the best 
way to do it?

One thing thing that I couldn't find in Marks example code is a way to 
pass custom error messages on a per field basis. right now I am getting 
basic "invalid" or "missing" errors.

Below is the very basic code I have working thus far. (I've not tweaked 
the regex beyond anything very basic at this stage.)
I'd like to be able to pass error messages like: (for username) "must be 
at least 8 characters"
and if the passwords don't match: "Your passwords don't match" And so on for
the other fields.

I thought putting:
err_username   => 'Username must be over 6 characters',
Into the "msgs" hash would force that message, but it doesn't appear to 
be working, I still get the "Invalid" message.

Can anyone give me pointers in this regard?

many thanks

Rgds

Franki

          my ($results,$err_page) = $self->check_rm('start_window', {
                         required => [qw/
                                        username
                                        password
                                        password2
                                        muncipality_name
                                        muncipality_number
                                        muncipality_street
                                        muncipality_city
                                        muncipality_state
                                        muncipality_zip
                                        muncipality_auth_officer
                                        muncipality_phone
                                     /],
                         optional => [qw/
                                        muncipality_fax
                                        muncipality_email
                                     /],
                         constraints => {
                                # required params
                                username                => '/\w{4}/',
                                password                => '/\w{6}/',
                                password2               => '/\w{6}/',
                                muncipality_name        => '/\w{2}/',
                                muncipality_number      => '/\w{1}/',
                                muncipality_street      => '/\w{3}/',
                                muncipality_city        => '/\w{3}/',
                                muncipality_state       => '/\w{2}/',
                                muncipality_zip         => '/\d{3}/',
                                muncipality_auth_officer=> '/\w{3}/',
                                muncipality_phone       => '/\d{6}/',
                                # optional params
                                muncipality_fax         => '/\d{6}/', # 
make sure the fax  is over 6 digits.
                                muncipality_email       => '/\w{5}/', # 
make sure the email is valid.
                                        
},                                    
                        # trim leading and trailing whitespace from all 
the valid fields.
                        filters         => ['trim'],
                        msgs=>{
                                any_errors => 'err__',
                                prefix     =>'err_',
                        },         
          });





---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[EMAIL PROTECTED]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[EMAIL PROTECTED]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to