开发者

Is the filter executed first then the validator in the Zend Framework

开发者 https://www.devze.com 2023-03-27 14:02 出处:网络
If I had this code $field = new Zend_Form_Element(); $field->开发者_运维百科;addValidator(new Zend_Validate_Alnum());

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'));
0

精彩评论

暂无评论...
验证码 换一张
取 消