HTML_QuickFormを使って、select要素にオプション(選択リストに表示される項目)を追加する方法のメモです。
フォームオブジェクトに追加するときにオプションを指定する例:
PHP:
-
-
$form->addElement('select', 'sel_bar','ラベル名', $options,$attr);
フォームオブジェクトに追加した後にオプションを指定する例:
PHP:
-
-
$elem =& $form->getElement('select_element');
-
foreach ($rows as $row) {
-
$elem->addOption($name,$row['id']);
-
}
select要素のソースの抜粋です。
PHP:
-
/**
-
* Adds a new OPTION to the SELECT
-
*
-
* @param string $text Display text for the OPTION
-
* @param string $value Value for the OPTION
-
* @param mixed $attributes Either a typical HTML attribute string
-
* or an associative array
-
* @since 1.0
-
* @access public
-
* @return void
-
*/
-
function addOption($text, $value, $attributes=null)
-
// 略