Is the filter executed first then the validator in the Zend Framework
If I had this code
$field = new Zend_Form_Element();
$field->开发者_运维百科;addValidator(new Zend_Validate_Alnum());
$field->setFilter(new Zend_Filter_StringToLower());
is the check for only alphanumeric characters executed after the string has been transformed to lower case?
Yes. The filter is activated by the element's getValue()
method.
In Zend/Form/Element.php, method isValid:
$this->setValue($value);
$value = $this->getValue();
getValue
call the filters on the data, before the value is passed to the validators. So yes, the value is filtered before validation. You can test it with:
$field = new Zend_Form_Element('test');
$field->addValidator(new Zend_Validate_Alnum());
// Display bool(false)
var_dump($field->isValid('A,B'));
$field->addFilter(new Zend_Filter_Alnum());
// Display bool(true)
var_dump($field->isValid('A,B'));
精彩评论