fuel/core — Issue #771: Some weird functionality on Validator
Author: odiel
Created: 2012-01-12 03:03:39+00:00
State: open

Hi

I really likes this framework. I'm using it on some personal applications. Trying the Validator I found some weird behavior when I use it like this:

$validator = Validation::forge('validator');
$validator->add('username', 'Username')
->add_rule('required')
->add_rule('min_length', 3)
->add_rule('max_length', 12)
->add_rule('valid_string', 'alpha');
$validator->add('c_password', 'Confirm password')
->add_rule('required');
$validator->add('password', 'Password')
->add_rule('required')
->add_rule('min_length', 3)
->add_rule('max_length', 20)
->add_rule('match_field', 'c_password');
$validator->add('email', 'Email')
->add_rule('required')
->add_rule('valid_email')
->add_rule('match_field', 'c_email');
$validator->add('c_email', 'Confirm email')
->add_rule('required');

if ($validator->run(array('username'=>$username, 'email'=>$email, 'c_password'=>$c_password, 'password'=>$password))){
}

If password and c_password not match I get this error: The field Password must match the field c_password.

I think the error must have the field label instead the field name. I fix it manually going into: core/lang/en/validation.php and change:

...
'match_field' => 'The field :label must match the field :param:1.',
...

for this:

...
'match_field' => 'The field :label must match the field :param:2.',
...

then on my validator rule add a second parameter:

...->add_rule('match_field', 'c_password', 'Confirm password');

That solve the problem, but I think is a temporary solution.

Hope the core team can fix it for the next release.

Keep FuelPhp burning...

Odiel