0
我正在構建選擇下拉列表,當表單提交併通過電子郵件發送給我時,它提交的是選定的下拉列表ID,而不是下拉選項的「值」。獲取數組下拉列表項的值不是ID
$result = db_query('SELECT title FROM {node} WHERE type = :type', array(
':type' => 'location',
))->fetchCol();
$items = array();
foreach ($result as $key => $value) {
$items[] = $value;
}
$form['location'] = array(
//'#prefix' => print_r($result),
'#type' => 'select',
'#options' => $items,
'#attributes' => array('class' => array('search-form'))
);
我嘗試使用$ i ++在想法,但沒有把握正確的。
//SELECT LOCATION
$result = db_query('SELECT title FROM {node} WHERE type = :type', array(
':type' => 'location',
))->fetchCol();
$items = array();
$i = 0;
foreach ($result as $key => $value) {
$items[] = $value;
$++;
}
$form['location'] = array(
//'#prefix' => print_r($result),
'#type' => 'select',
'#options' => $items[$i],
'#attributes' => array('class' => array('search-form'))
);