1
我使用下面的代碼將am_category表中的所有類別轉換爲表單中的下拉框。有用。但是在提交表單時,我需要category.ID而不是名稱。人們通常如何處理像這樣的查找表?如何使用查找表?
$category_result = db_query("SELECT id, name FROM {am_category}");
$categories = array();
foreach($category_result as $row)
{
$categories[$row->id] = t($row->name);
}
$form['category_options'] = array(
'#type' => 'value',
'#value' => $categories
);
$form['category']['category'] = array(
'#title' => t('Category'),
'#type' => 'select',
'#description' => t('Please select the category of this achievement.'),
'#options' => $form['category_options']['#value']
);
感謝。正是我在找什麼。 – Napoleon