I want to populate select option from loop
$form['vote']['selected'] = array(
'#type' => 'select',
'#title' => 'Select',
'#name' => 'name',
);
foreach($loop as $row)
$form['vote']['selected']['#options'] = array($row->id => $row->name);
}
return $form;
Need some help?
This is the standard way to do it:
You might also look at the
fetchAllKeyed
method of the database query which is a handy shortcut to get data from the database into a keyed array suitable for select lists:The above will produce exactly the same as the
foreach
loop above.