By hazamonzo on
Hello folks, im trying to create a simple select box for one of my forms.
So far i have created the select box option array by doing this:
$companies_result = db_query("SELECT nid, company_name FROM {node_companies}");
while ($record = db_fetch_array($companies_result)) {
$companies_arr[$record['nid']] = $record['company_name'];
}
//and the form below like this
$form['vessel_owner_id'] = array(
'#type' => 'select',
'#title' => t('Vessel Owner'),
'#options' => $companies_arr,
'#description' => t('Please choose an option.'),
);
Now this form works fine and stores the vessel_owner_id into my table but if i want to edit this node, i would like the select box to be already selected on the option that was chosen when the node was created.
The HTML would be something like this:
<option value="4">Company 1</option>
Any ideas?
Cheers
Comments
See forms reference
Specifically, #default_value.