Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.8.2
-
Component/s: Zend_Filter_Input
-
Labels:None
Description
Zend_Filter_Input skips ALLOW_EMPTY metacommand processing if any validator is applied to the field:
/** * @param array $validatorRule * @return void */ protected function _validateRule(array $validatorRule) { .... /** * Evaluate the inputs against the validator chain. */ if (count((array) $validatorRule[self::FIELDS]) > 1) { if (!$validatorRule[self::VALIDATOR_CHAIN]->isValid($data)) { $this->_invalidMessages[$validatorRule[self::RULE]] = $validatorRule[self::VALIDATOR_CHAIN]->getMessages(); $this->_invalidErrors[$validatorRule[self::RULE]] = $validatorRule[self::VALIDATOR_CHAIN]->getErrors(); return; } ....
foreach ($field as $value) {
if (empty($value)) {
if ($validatorRule[self::ALLOW_EMPTY] == true) {
continue;
}
if ($validatorRule[self::VALIDATOR_CHAIN_COUNT] == 0) {
$notEmptyValidator = $this->_getValidator('NotEmpty');
$notEmptyValidator->setMessage($this->_getNotEmptyMessage($validatorRule[self::RULE], $fieldKey));
$validatorRule[self::VALIDATOR_CHAIN]->addValidator($notEmptyValidator);
}
}
That was probably done to avoid 'empty value' messages duplication since these messages may come from Validators as well as from Zend_Filter_Input::ALLOW_EMPTY metacommand.
There are two options: