API16

JHtmlSelect/radiolist

From Joomla! Documentation

< API16:JHtmlSelect
Revision as of 21:58, 13 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Generates an HTML radio list.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

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[edit]

string HTML for the select list

Defined in[edit]

libraries/joomla/html/html/select.php

Importing[edit]

jimport( 'joomla.html.html.select' );

Source Body[edit]

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;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />