Actions

API15

JHTMLSelect/radiolist

From Joomla! Documentation

< API15:JHTMLSelect
Revision as of 13:31, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
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

[<! 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

<CodeExamplesForm />