We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Validator Identical problem in 2.0.4?

It was working before, but suddenly, the validator stopped working correctly.

    $test = new Text('test', [
         'placeholder' => 'Test',
         'class' => 'pure-input-1'
     ]);

     $test->addValidator(new Identical([
         'value' => 'abc',
         'message' => 'Security token (TEST) validation failed.',
     ]));

     $this->add($test);

On the form I input exactly the same "abc" and submit. View: echo $form->render('test');

if (! $form->isValid($request->getPost()) ) {
    // Is not valid
}

I checked the POST value, the form object's value, its the same, if I do a == comparison, i get true.

Is this a new issue with the validator in 2.0.4?



4.0k
Accepted
answer

Bad parameter key name. Change value to accepted

    $test = new Text('test', [
         'placeholder' => 'Test',
         'class' => 'pure-input-1'
     ]);

     $test->addValidator(new Identical([
         'accepted' => 'abc',
         'message' => 'Security token (TEST) validation failed.',
     ]));

     $this->add($test);

thanks Paulius. Wasted 3 hours with this small change that KorsaR did and no one bothered listing it on the change log. I don't really get the logic of this "fix"; change the code to match the docs instead of changing the docs to match the code. With every release, Phalcon team keep changing every part of the framework, without thinking of the backwards compatibily, like is in alpha stage and not production ready.