API16:JHtmlSelect/radiolist
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Generates an HTML radio list.
Description:JHtmlSelect/radiolist
Syntax
static radiolist($data, $name, $attribs=null, $optKey= 'value', $optText= 'text', $selected=null, $idtag=false, $translate=false)
| Parameter Name | Default Value | Description |
|---|---|---|
| $data | An array of objects | |
| $name | The value of the HTML name attribute | |
| $attribs | null | Additional HTML attributes for the <select> tag |
| $optKey | 'value' | The key that is selected |
| $optText | '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
public static function radiolist( $data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false, $translate = false ) { reset($data); $html = ''; if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } $id_text = $idtag ? $idtag : $name; foreach ($data as $ind => $obj) { $k = $obj->$optKey; $t = $translate ? JText::_($obj->$optText) : $obj->$optText; $id = (isset($obj->id) ? $obj->id : null); $extra = ''; $extra .= $id ? ' id="' . $obj->id . '"' : ''; if (is_array($selected)) { foreach ($selected as $val) { $k2 = is_object($val) ? $val->$optKey : $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 . '/>' . "\n\t" . '<label for="' . $id_text . $k . '" id="' . $id_text . $k . '-lbl" class="radiobtn_'.strtolower($obj->$optText).'">'. $t .'</label>'; } $html .= "\n"; return $html; }
[Edit See Also] SeeAlso:JHtmlSelect/radiolist
Examples
<CodeExamplesForm />
