Maybe I'm missing something, but here's the problem:
I have a form in which and empty value in one input may or may not be valid
depending on context. I have a custom validator to determine that. But,
when I call ->isValid() on the form, my custom validator may not be called
depending on the 'required' and 'allow_empty' settings I've given to the
Factory class. For example, I could set 'allow_empty' to 'true' in the
spec, but here's what happens:
Let's say I give it an empty value, and 'allow_empty' is TRUE:
(Zend\InputFilter\BaseInputFilter, starting at line 162):
foreach ($inputs as $name) {
$input = $this->inputs[$name];
if (!array_key_exists($name, $this->data)
|| (null === $this->data[$name])
|| (is_string($this->data[$name]) &&
strlen($this->data[$name]) === 0)
) {
if ($input instanceof InputInterface) {
// - test if input is required
if (!$input->isRequired()) {
$this->validInputs[$name] = $input;
continue;
}
// - test if input allows empty
if ($input->allowEmpty()) {
$this->validInputs[$name] = $input; // <- WTF?
There are other validators!
continue;
}
}
// make sure we have a value (empty) for validation
$this->data[$name] = '';
}
if ($input instanceof InputFilterInterface) {
if (!$input->isValid()) {
$this->invalidInputs[$name] = $input;
$valid = false;
continue;
}
$this->validInputs[$name] = $input;
continue;
}
if ($input instanceof InputInterface) {
if (!$input->isValid($this->data)) {
// Validation failure
$this->invalidInputs[$name] = $input;
$valid = false;
if ($input->breakOnFailure()) {
return false;
}
continue;
}
$this->validInputs[$name] = $input;
continue;
}
The assumption is that if we allow a field to be empty, and it IS empty,
it's valid. Period, full stop, screw you and your other validators.
Short of extending InputFilter, Input, and Factory, to override this
behavior, is there something else that can be done? Like I said, am I just
missing something?
(Also, one page of docs for the entire InputFilter module? Really?)
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Zend-InputFilter-can-t-handle-an-empty-value-based-on-context-tp4659287.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]