mosHTML::treeSelectList

Last reviewed: Not reviewed
phpDocumentor

mosHTML::treeSelectList

Generates an HTML select list from a tree based query list.

Syntax

string treeSelectList ( array &$options, int $id, array $preload, string $tag_name,
                                             string $tag_attribs, string $key, string $text, mixed $selected )

$options
is an array of objects that have been returned by a database query or the mosHTML::makeOption method.  Each object in the array must contain id and parent properties.
$id
is the id of the current list item.
$preload
is an array of objects that will be used to preload the selection list.  The objects might have been returned by a database query or the mosHTML::makeOption method.  The array may be empty.
$tag_name
is the name attribute of the HTML <select> tag.
$tag_attribs
is a string containing any additional attributes that you want to assign to the HTML <select> tag.
$key
is the name of the class variable holding the option 'value'.  Should generally be 'value'
$text
is the name of the class variable holding the option 'text'.  Should generally be 'text'.
$selected
is either a string value for a single value select list or an array for a multiple value select list.

Examples

Example 1: a single value select list:

$query = "SELECT * FROM #__menu WHERE menutype='mainmenu' ORDER BY ordering";
$database->setQuery( $query );
$src_list = $database->loadObjectList();
$selected = array();
$selected[] = mosHTML::makeOption( '2' );
echo mosHTML::treeSelectList( &$src_list, 1, array(), 'cid',
                 'class="inputbox" size="1"', 'value', 'text', $selected );

which might produce:

<select name="cid" class="inputbox" size="1">
  <option value="33">Joomla License</option>
  <option value="2" selected="selected">News</option>
  <option value="48">.      <sup>L</sup> All that's fit to print</option>
 
  <option value="49">.      <sup>L</sup> Everything else</option>
  <option value="39">Blog</option>
  <option value="4">Links</option>
  <option value="3">Contact Us</option>
  <option value="27">Search</option>
</select>
 

which will render as:

Example 2: a multiple value select list:

$query = "SELECT * FROM #__menu WHERE menutype='mainmenu' ORDER BY ordering";
$database->setQuery( $query );
$src_list = $database->loadObjectList();
 
$preload = array();
$preload[] = mosHTML::makeOption( '0', 'Select one or more menu options' );
 
$selected = array();
$selected[] = mosHTML::makeOption( '2' );
$selected[] = mosHTML::makeOption( '4' );
echo mosHTML::treeSelectList( &$src_list, 1, $preload, 'cid',
        'class="inputbox" size="10" multiple="true"', 'value', 'text', $selected );

might produce:

<select name="cid" class="inputbox" size="10" multiple="true">
  <option value="0">Select one or more menu options</option>
  <option value="33">Joomla License</option>
  <option value="2" selected="selected">News</option>
  <option value="48">.      <sup>L</sup> All that's fit to print</option>
  <option value="49">.      <sup>L</sup> Everything else</option>
  <option value="39">Blog</option>
  <option value="4" selected="selected">Links</option>
  <option value="3">Contact Us</option>
  <option value="27">Search</option>
</select>
 

which will render as:


Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Wednesday, 28 September 2005 )