zend validate multi select box
Asked Answered
D

1

6

i am using zend validations in my form and i could not validate a multi select box in my form.

This is my multi select element in the form:

$days = new Zend_Form_Element_Select('day');
$days->setLabel('Days')
->addMultiOptions($total_days)
->setRequired(true)
->addValidator('NotEmpty')
->setAttrib('multiple', 'multiple');

I get the following error during form submission, even when i select some option in the multiselect box:

Array was not found in the haystack

And i see the following code in Zend/Validate/InArray.php, that can validate only single form elements, but not arrays:

public function isValid($value)
{
$this->_setValue($value);
if (in_array($value, $this->_haystack, $this->_strict)) 
{
return true;
}
}

But how can i resolve the error?

Deeannadeeanne answered 23/4, 2011 at 13:46 Comment(0)
D
11

To have multi select elements in your form, you should be using Zend_Form_Element_Multiselect, not Zend_Form_Element_Select, eg:

$days = new Zend_Form_Element_Multiselect('day');
$days->setLabel('Days')
->addMultiOptions($total_days)
->setRequired(true)
->addValidator('NotEmpty');
Desman answered 23/4, 2011 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.