Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to use custom validator? It wont stop if fails!

Inside a \Phalcon\Forms\Form I add my own valdator:

$item->addValidator(new \CustomEmailValidator(array(
  'message' => 'bad!')
));

this looks like:

class CustomEmailValidator extends Phalcon\Validation\Validator implements Phalcon\Validation\ValidatorInterface

{

public function validate(\Phalcon\Validation $validator, $attribute)

{

return false;

}

}

the problem is, no matter what I return, it wont stop the validator. I expect it failed, just like I had set any other validator



64.2k
Accepted
answer
edited Oct '15

my message is a bit spammy, but i remeber when i was trying same stuff I couldnt make it work, then I moved to 2.1.x where validations seems to be working.

if it is any help there are some additinal validators ( i think ) in incubator github repo. Check their code and try it yourself to see if any changes apear.



12.2k

something like that. All I had to do this before returning false, adding the message:

$validator->appendMessage(new \Phalcon\Validation\Message('message', $attribute, 'CustomEmailValidator'));