views:

1221

answers:

3

Hello I have an array like this :

Array ( 
  [id] => 1 
  [code] => Dep98 
  [description] => Hello World 
  [facility] => Array ( 
    [0] => FacName1 
    [1] => FacName2
  )
)

But when I populate this array to Zend_Form it only show data in textboxes elements having same id as defined in array index not in multiselect dropdown element. for example:

'code'        id is also define in form's first textbox element,
'description' id is also define in form's second textbox element,
'facility'    id is also define in form's third MultiOptions element

But in MultiOptions it does not show any record.

A: 

What exactly do you want in the drop down box?

The array you pass to multiOptions must be in the form of value => title.

You may want to loop through your results and generate an options array.

For example

$options = array();
foreach ( $data as $value ) {    
  $options[$value['id']] = $value['description'];
}

$select = Zend_From_Element_Select("select_field");
$select->multiOptions($options);
Travis
A: 

I agree with Travis, you should pass an array with following values to populate:

$vals = array('code'=>5, 
              'description' => 'testing', 
              'facility' => array(1=>'FacName2'));
$form->populate($vals);

But note this - options must be filled in the facility form element before attempting to populate or validate, dont expect facility value to be set if there is an empty list of options in the facility element.

gregor
A: 

Try this:

Array (

[id] => 1
[code] => Dep98
[description] => Hello World
[facility] => Array (
FacName1 => [0]
FacName2 => [1]
)
)

Behrang