HTML_QuickForm_hierselect::setOptions()

HTML_QuickForm_hierselect::setOptions() – select 要素の選択肢を設定する

Synopsis

require_once 'HTML/QuickForm/hierselect.php';

void HTML_QuickForm_hierselect::setOptions ( array $options )

Description

hierselect 内の select 要素の選択肢を設定します。実際に表示される選択肢の数は、 この関数に渡された配列の要素数によって決まることに注意しましょう。

Parameter

array $options

要素の選択肢の配列。次のような形式になります。


array(
  // 最初の要素の選択肢
  array(
    'key_1' => 'value 1',
    'key_2' => 'value 2',
    ...
    'key_N' => 'value N',
  ),
  // 2 番目の要素の選択肢
  array(
    'key_1' => array(
      'key_1_1' => 'value 1.1',
      'key_1_2' => 'value 1.2',
      ...
      'key_1_M1' => 'value 1.M1'
    ),
    'key_2' => array(
      'key_2_1' => 'value 2.1',
      'key_2_2' => 'value 2.2',
      ...
      'key_2_M2' => 'value 2.M2'
    ),
    ...
    'key_N' => array(
      'key_N_1' => 'value N.1',
      'key_N_2' => 'value N.2',
      ...
      'key_N_MN' => 'value N.MN'
    )
  )
  // それ以降の要素の選択肢
  ...
)
後に続く要素の選択肢には、ひとつ前の要素のすべての選択肢に対応する要素が含まれなければなりません。 選択肢のない select は HTML として無効な形式であり、hierselect の JavaScript が動作しなくなります。 Bug #5218 も参照ください。

Throws

例外はスローされません。

Note

This function can not be called statically.

since 3.2.2

Example

hierselect の選択肢の設定

<?php
$select1 
$select2 $select3 = array();

$select1[0] = 'Pop';
$select1[1] = 'Classical';
$select1[2] = 'Funeral doom';

// 2 つめの select
$select2[0][0] = '--- Artist ---';
$select2[0][1] = 'Red Hot Chil Peppers';
$select2[0][2] = 'The Pixies';
      
$select2[1][0] = '--- Artist ---';
$select2[1][1] = 'Wagner';
$select2[1][2] = 'Strauss';
      
$select2[2][0] = '--- Artist ---';
$select2[2][1] = 'Pantheist';
$select2[2][2] = 'Skepticism';
     
// 3 つめの select では CD の価格を選択します
$select3[0][0][0] = '--- Choose the artist ---';
$select3[0][1][0] = '15.00$';
$select3[0][2][1] = '17.00$';
$select3[1][0][0] = '--- Choose the artist ---';
$select3[1][1][0] = '15.00$';
$select3[1][2][1] = '17.00$';
$select3[2][0][0] = '--- Choose the artist ---';
$select3[2][1][0] = '15.00$';
$select3[2][2][1] = '17.00$';     

// 要素を作成します
$sel =& $form->addElement('hierselect''cds''Choose CD:');

// そして選択肢を追加します
$sel->setOptions(array($select1$select2$select3));
?>