HTML_QuickForm_hierselect::setOptions()

HTML_QuickForm_hierselect::setOptions() – Sets the options for the select elements

Synopsis

require_once 'HTML/QuickForm/hierselect.php';

void HTML_QuickForm_hierselect::setOptions ( array $options )

Description

Sets the options for the select elements within hierselect. Note that the actual number of selects that will be displayed is governed by the number of the elements in the array passed to this function.

Parameter

array $options

Array of options for the elements, having the following structure:


array(
  // options for the first element
  array(
    'key_1' => 'value 1',
    'key_2' => 'value 2',
    ...
    'key_N' => 'value N',
  ),
  // options for the second element
  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'
    )
  )
  // options for further elements
  ...
)
The options for subsequent elements should have keys for all options of the previous elements. Having a select without options is invalid HTML and will break hierselect's JavaScript. See also Bug #5218.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

since 3.2.2

Example

Setting the hierselect options

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

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

// second 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';
     
// Create a third select with prices for the cds
$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$';     

// Create the Element
$sel =& $form->addElement('hierselect''cds''Choose CD:');

// And add the selection options
$sel->setOptions(array($select1$select2$select3));
?>