1
votes

I have a list box in which all the name of the companies are displayed. When I click on search button it displays the result. But my selected search values are not displayed in the list box. It vanishes when I click on search button.

We could achieve this in PHP like so:

select
option if($_POST['a']==1){selected="selected"} > ibm option> 
select

But I want to implement the same thing in my select box in Zend Form. How can I do it?

This is the code I have currently for my Zend form select box:

$list = new Application_Model_Abc
$showlist  = $list ->List()

foreach($showlist as $key => $value)

$name = $value['cName']

$companyName->addMultiOption($value['id'], $name)


$this->addElement($companyName)
1

1 Answers

0
votes

first of all you have to pass value from your controller to zend form to make it selected default.

For example

$formObj->searchForm($a) // selected data to pass in form

And in zend form your will get in

public function searchForm($selected_value=NULL)
{

->addMultiOptions(array(''=>'-','7'=>'7','6'=>'6','5'=>'5','4'=>'4','3'=>'3'))
            ->setValue($selected_value)
}

let me know if i can help you more