API15:JHTMLSelect/radiolist
From Joomla! Documentation
Description
Generates an HTML radio list
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
radiolist($arr, $name, $attribs=null, $key= 'value', $text= 'text', $selected=null, $idtag=false, $translate=false)
| Parameter Name | Default Value | Description |
|---|---|---|
| $arr | An array of objects | |
| $name | The value of the HTML name attribute | |
| $attribs | null | Additional HTML attributes for the <select> tag |
| $key | 'value' | The key that is selected |
| $text | 'text' | The name of the object variable for the option value |
| $selected | null | The name of the object variable for the option text |
| $idtag | false | |
| $translate | false |
Returns
string HTML for the select list
Defined in
libraries/joomla/html/html/select.php
Importing
jimport( 'joomla.html.html.select' );
Source Body
function radiolist( $arr, $name, $attribs = null, $key = 'value', $text = 'text', $selected = null, $idtag = false, $translate = false )
{
reset( $arr );
$html = '';
if (is_array($attribs)) {
$attribs = JArrayHelper::toString($attribs);
}
$id_text = $name;
if ( $idtag ) {
$id_text = $idtag;
}
for ($i=0, $n=count( $arr ); $i < $n; $i++ )
{
$k = $arr[$i]->$key;
$t = $translate ? JText::_( $arr[$i]->$text ) : $arr[$i]->$text;
$id = ( isset($arr[$i]->id) ? @$arr[$i]->id : null);
$extra = '';
$extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
if (is_array( $selected ))
{
foreach ($selected as $val)
{
$k2 = is_object( $val ) ? $val->$key : $val;
if ($k == $k2)
{
$extra .= " selected=\"selected\"";
break;
}
}
} else {
$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>";
}
$html .= "\n";
return $html;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples