Zend validate multi select box

I use zend checks in my form, and I could not check the multiple select box in my form.

This is my multi-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 while submitting a form, even when I select an option in the multi selector field:

Array not found in haystack

And I see the following code in Zend / Validate / InArray.php, which can only check individual 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 solve this error?

+6
source share
1 answer

To have multiple selections in your form, you should use Zend_Form_Element_Multiselect and not Zend_Form_Element_Select, for example:

 $days = new Zend_Form_Element_Multiselect('day'); $days->setLabel('Days') ->addMultiOptions($total_days) ->setRequired(true) ->addValidator('NotEmpty'); 
+11
source

Source: https://habr.com/ru/post/886531/


All Articles