In an InputFilter I have this code:
$password = new Input('password');
$password->setRequired(false)
->getValidatorChain()
->attach(new Validator\StringLength(6));
$password->getFilterChain()
->attach($this->passwordHash);
The problem is that the filter is applying to the value before the validation, so the validator always returns true.
I was wondering if there is any way to do the filtering after the validation.
It seems odd to filter after validation as the input before validation could be edited by the filters. Like strip tags or trim the string. If you do use a filter like
\Zend\I18n\Filter\Alnum()you could let it remove the whitespaces. So see it as bad practice to filter after validating your input.E.g., take those filters:
Notice that the begin value differs from the result. But you can filter after validation, but I guess you have to it by yourself. So you could add a method to your inputfilter or form which you call after validation. For example:
In your controller you can do this for example: