I am creating multiple select element like this and it is showed successfully on form:
$element = new Zend_Form_Element_Multiselect('clinics');
$element->setLabel("Clinics");
$element->setAttrib( 'style','width: 240px' );
$element->setMultiOptions( array( '1'=>'clinic1', '2'=>'clinic2' ) );
After rendering above element it shows the following html in html source:
<select name="clinics[]" id="clinics" multiple="multiple" style="width: 240px" size="5" class="required" tabindex="41">
<option value="1" label="clinic1">clinic1</option>
<option value="2" label="clinic2">clinic2</option>
</select>
But when I submit the form with two selected fields and print_r the result like this:
$request = $this->getRequest();
$form = new Patient_Form_Patient( $formOptions );
if ( $request->isPost() ) {
if ( $form->isValid( $request->getPost() ) ) {
$values = $form->getValues();
print_r($values);die();
}
}
It stores only first selected option in array but not all selected elements:
Array
(
[clinics] => Array
(
[0] => 1
)
[save] => Submit
)
Can someone help that how can I submit multiple values ?
setMultiOptions()
function while creating element but should I any thing else. Thanks – Buttockmultiple
attribute is already set, else you wouldn't be able to select more than one option in your browser. – Pettish