Source code for file /joomla/html/html/select.php
Documentation is available at select.php
* @version $Id: select.php 13341 2009-10-27 03:03:54Z ian $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
* Utility class for creating HTML select lists
* @package Joomla.Framework
* @param string The value of the option
* @param string The text for the option
* @param string The returned object property name for the value
* @param string The returned object property name for the text
function option( $value, $text=
'', $value_name=
'value', $text_name=
'text', $disable=
false )
$obj->$value_name =
$value;
$obj->$text_name =
trim( $text ) ?
$text :
$value;
$obj->disable =
$disable;
* @param string The text for the option
* @param string The returned object property name for the value
* @param string The returned object property name for the text
function optgroup( $text, $value_name =
'value', $text_name =
'text' )
$obj->$value_name =
'<OPTGROUP>';
$obj->$text_name =
$text;
* Generates just the option tags for an HTML select list
* @param array An array of objects
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @param mixed The key that is selected (accepts an array or a string)
* @returns string HTML for the select list
function options( $arr, $key =
'value', $text =
'text', $selected =
null, $translate =
false )
foreach ($arr as $i =>
$option)
$element =
& $arr[$i]; // since current doesn't return a reference, need to do this
$id =
( isset
( $element['id'] ) ?
$element['id'] :
null );
if(isset
($element['disable']) &&
$element['disable']) {
$extra .=
' disabled="disabled"';
$id =
( isset
( $element->id ) ?
$element->id :
null );
if(isset
( $element->disable ) &&
$element->disable) {
$extra .=
' disabled="disabled"';
// This is real dirty, open to suggestions,
// barring doing a propper object to handle it
if ($k ===
'<OPTGROUP>') {
$html .=
'<optgroup label="' .
$t .
'">';
} else if ($k ===
'</OPTGROUP>') {
//if no string after hypen - take hypen out
$splitText =
explode( ' - ', $t, 2 );
if(isset
($splitText[1])){ $t .=
' - '.
$splitText[1]; }
//$extra .= $id ? ' id="' . $arr[$i]->id . '"' : '';
foreach ($selected as $val)
$extra .=
' selected="selected"';
$extra .=
( (string)
$k == (string)
$selected ?
' selected="selected"' :
'' );
// ensure ampersands are encoded
$html .=
'<option value="'.
$k .
'" '.
$extra .
'>' .
$t .
'</option>';
* Generates an HTML select list
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @param mixed The key that is selected (accepts an array or a string)
* @returns string HTML for the select list
function genericlist( $arr, $name, $attribs =
null, $key =
'value', $text =
'text', $selected =
NULL, $idtag =
false, $translate =
false )
$html =
'<select name="'.
$name .
'" id="'.
$id .
'" '.
$attribs .
'>';
$html .=
JHTMLSelect::Options( $arr, $key, $text, $selected, $translate );
* Generates a select list of integers
* @param int The start integer
* @param int The end integer
* @param int The increment
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @param string The printf format to be applied to the number
* @returns string HTML for the select list
function integerlist( $start, $end, $inc, $name, $attribs =
null, $selected =
null, $format =
"" )
for ($i=
$start; $i <=
$end; $i+=
$inc)
$fi =
$format ?
sprintf( "$format", $i ) :
"$i";
$arr[] =
JHTML::_('select.option', $fi, $fi );
return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selected );
* Generates an HTML radio list
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @returns string HTML for the select list
function radiolist( $arr, $name, $attribs =
null, $key =
'value', $text =
'text', $selected =
null, $idtag =
false, $translate =
false )
for ($i=
0, $n=
count( $arr ); $i <
$n; $i++
)
$t =
$translate ?
JText::_( $arr[$i]->$text ) :
$arr[$i]->$text;
$id =
( isset
($arr[$i]->id) ?
@$arr[$i]->id :
null);
$extra .=
$id ?
" id=\"" .
$arr[$i]->id .
"\"" :
'';
foreach ($selected as $val)
$extra .=
" selected=\"selected\"";
$extra .=
((string)
$k == (string)
$selected ?
" checked=\"checked\"" :
'');
$html .=
"\n\t<input type=\"radio\" name=\"$name\" id=\"$id_text$k\" value=\"".
$k.
"\"$extra $attribs />";
$html .=
"\n\t<label for=\"$id_text$k\">$t</label>";
* Generates a yes/no radio list
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @returns string HTML for the radio list
function booleanlist( $name, $attribs =
null, $selected =
null, $yes=
'yes', $no=
'no', $id=
false )
return JHTML::_('select.radiolist', $arr, $name, $attribs, 'value', 'text', (int)
$selected, $id );