"Joshua Ross" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
I am having a problem with Zend_Filter_Input when attempting to validate an
array of values using the fields meta command. What happens is that ZFI
passes the array of values to my filter which correctly returns true and
then ZFI passes each value separately which fails. Here is my
code(simplified) pretty much straight from the doc:
$validators = array('password_check' => array('StringEquals',
'presence' => 'required',
'fields' => array('password0', 'password1'));
$input = new Zend_Filter_Input(array(), $validators,
$this->getRequest()->getPost());
$input->addNamespace('Local_Validate');
if (!$input->isValid()) {
}
What happens is StringEquals is called three times, once with an array,
and once with each string. Some debug output dumping the value passed to
my StringEquals validator produces the following:
array(2) {
["password0"] => string(9) "Testing1!"
["password1"] => string(9) "Testing1!"
}
string(9) "Testing1!"
string(9) "Testing1!"
So I looked into ZFI and it appears it handles arrays of fields (line 720
in ZF 1.0.0 v5344) but then it continues to evaluate all fields in the
data array *seperately* validating it against the current validator chain
which happens to be the validator StringEquals which only validates
arrays... which of course returns false.
Basically, it appears either I am missing something or having the fields
meta command set to an array will not work if the validator validates that
the value is in fact an array. Anyone else come across this? Should my
validator simply return true if the value is not an array? I'm not sure I
care too much for that work around. To me, if you pass the fields meta
command with an array value it should only validate the array, not each
seperately. Any help is appreciated,
Thanks
Josh
The following if stmt fixes the issue:
// Added the below if check
if (1 == count($validatorRule[self::FIELDS])) {
if (!$validatorRule[self::VALIDATOR_CHAIN]->isValid($value)) {
$this->_invalidMessages[$validatorRule[self::RULE]] =
$validatorRule[self::VALIDATOR_CHAIN]->getMessages();
$this->_invalidErrors[$validatorRule[self::RULE]] =
$validatorRule[self::VALIDATOR_CHAIN]->getErrors();
unset($this->_validFields[$fieldKey]);
$failed = true;
if ($validatorRule[self::BREAK_CHAIN]) {
return;
}
}