Class Summary HTML_QuickForm_hierselect

Class Summary HTML_QuickForm_hierselect – Class to dynamically create chained HTML Select elements, each select changes the content of the next.

Description

Class to dynamically create "chained" HTML Select elements. Choosing an option in the first <select> changes the content of the second select and so on.

This element is considered as a group. Selects will be named groupName[0], groupName[1], ...

Creating a hierselect element based on values from a database table

<?php
require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm('example');

$form->setDefaults(array('test' => array('4','15')));
$sel =& $form->addElement('hierselect''test''Test:'null'/');

$mainOptions $db->getAssoc('select pkparent, par_desc from parent');

$result $db->query("select fk_parent, pkchild, chi_desc from child");
while (
$result->fetchInto($row)) {
    
$secOptions[$row[0]][$row[1]] = $row[2];
}
// Using setMainOptions and setSecOptions is now deprecated 
// use setOptions.

$sel->setOptions(array($mainOptions$secOptions));

$form->display();
?>

Creating more than two select elements is just as simple.

Creating a hierselect element with three select elements

<?php
require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm('example');

$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));

$form->display();
?>

Class Trees for HTML_QuickForm_hierselect

HTML_QuickForm_hierselect Inherited Methods

Inherited from HTML_QuickForm_group
Method Name Summary
Constructor HTML_QuickForm_group::HTML_QuickForm_group() Class constructor
HTML_QuickForm_group::accept() Accepts a renderer
HTML_QuickForm_group::exportValue() As usual, to get the group's value we access its elements and call
HTML_QuickForm_group::getElementName() Returns the element name inside the group such as found in the html form
HTML_QuickForm_group::getElements() Gets the grouped elements
HTML_QuickForm_group::getFrozenHtml() Returns the value of field without HTML tags
HTML_QuickForm_group::getGroupType() Gets the group type based on its elements Will return 'mixed' if elements contained in the group are of different types.
HTML_QuickForm_group::getName() Returns the group name
HTML_QuickForm_group::getValue() Returns the value of the group
HTML_QuickForm_group::onQuickFormEvent() Called by HTML_QuickForm whenever form event is made on this element
HTML_QuickForm_group::setElements() Sets the grouped elements
HTML_QuickForm_group::setName() Sets the group name
HTML_QuickForm_group::setValue() Sets values for group's elements
Inherited from HTML_QuickForm_element
Method Name Summary
Constructor HTML_QuickForm_element::HTML_QuickForm_element() Class constructor
HTML_QuickForm_element::accept() Accepts a renderer
HTML_QuickForm_element::apiVersion() Returns the current API version
HTML_QuickForm_element::exportValue() Returns a 'safe' element's value
HTML_QuickForm_element::freeze() Freeze the element so that only its value is returned
HTML_QuickForm_element::getFrozenHtml() Returns the value of field without HTML tags
HTML_QuickForm_element::getLabel() Returns display text for the element
HTML_QuickForm_element::getName() Returns the element name
HTML_QuickForm_element::getType() Returns element type
HTML_QuickForm_element::getValue() Returns the value of the form element
HTML_QuickForm_element::isFrozen() Returns whether or not the element is frozen
HTML_QuickForm_element::onQuickFormEvent() Called by HTML_QuickForm whenever form event is made on this element
HTML_QuickForm_element::setLabel() Sets display text for the element
HTML_QuickForm_element::setName() Sets the input field name
HTML_QuickForm_element::setPersistantFreeze() Sets wether an element value should be kept in an hidden field when the element is frozen or not
HTML_QuickForm_element::setValue() Sets the value of the form element
HTML_QuickForm_element::unfreeze() Unfreezes the form element
Class constructor (Previous) Class constructor (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.