Displaying Array in Select - FORM API Drupal
Posted
by Krishma
on Stack Overflow
See other posts from Stack Overflow
or by Krishma
Published on 2010-05-03T16:54:23Z
Indexed on
2010/05/03
16:58 UTC
Read the original article
Hit count: 367
Hi:
I want to add key(type_id) and value(type_description) to select in drupal form API
$result_x->product_types->RPMProductType is array result from Database :- array(4) { [0]=> object(stdClass)#18 (2) { ["type_description"]=> string(10) "Calendered" ["type_id"]=> int(1) } [1]=> object(stdClass)#19 (2) { ["type_description"]=> string(8) "Extruded" ["type_id"]=> int(2) } [2]=> object(stdClass)#20 (2) { ["type_description"]=> string(6) "Molded" ["type_id"]=> int(3) } [3]=> object(stdClass)#21 (2) { ["type_description"]=> string(5) "Other" ["type_id"]=> int(4) } }
foreach ($result_x->product_types->RPMProductType as $data)
{
$form['manufacturer_add_new_sales']['product_type'] = array(
'#type' => 'select',
'#title' => t('Product Type'),
'#options'=>array($data->type_id=>$data->type_description),
);
}
When do so I am getting only last value i.e Other. How to correctly loop to bind Select to display all the array Key - Values.
Thank you in advance.
© Stack Overflow or respective owner