API16

JHtmlSelect/genericlist

From Joomla! Documentation

< API16:JHtmlSelect

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 selection list.


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

Syntax[edit]

static genericlist($data, $name, $attribs=null, $optKey= 'value', $optText= 'text', $selected=null, $idtag=false, $translate=false)
Parameter Name Default Value Description
$data An array of objects, arrays, or scalars.
$name The value of the HTML name attribute.
$attribs null Additional HTML attributes for the <select> tag. This can be an array of attributes, or an array of options. Treated as options if it is the last argument passed. Valid options are:
$optKey 'value'
$optText 'text'
$selected null
$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 genericlist(
        $data, $name, $attribs = null, $optKey = 'value', $optText = 'text',
        $selected = null, $idtag = false, $translate = false
) {
        // Set default options
        $options = array_merge(
                JHtml::$formatOptions,
                array(
                        'format.depth' => 0,
                        'id' => false,
                )
        );
        if (is_array($attribs) && func_num_args() == 3) {
                // Assume we have an options array
                $options = array_merge($options, $attribs);
        } else {
                // Get options from the parameters
                $options['id'] = $idtag;
                $options['list.attr'] = $attribs;
                $options['list.translate'] = $translate;
                $options['option.key'] = $optKey;
                $options['option.text'] = $optText;
                $options['list.select'] = $selected;
        }
        $attribs = '';
        if (isset($options['list.attr'])) {
                if (is_array($options['list.attr'])) {
                        $attribs = JArrayHelper::toString($options['list.attr']);
                } else {
                        $attribs = $options['list.attr'];
                }
                if ($attribs != '') {
                        $attribs = ' ' . $attribs;
                }
        }

        $id = $options['id'] !== false ? $options['id'] : $name;
        $id = str_replace(array('[', ']'), '', $id);

        $baseIndent = str_repeat($options['format.indent'], $options['format.depth']++);
        $html = $baseIndent . '<select' . ($id !== '' ? ' id="' . $id . '"' : '')
                . ' name="' . $name . '"'
                . $attribs . '>'
                . $options['format.eol']
                . self::options($data, $options)
                . $baseIndent . '</select>'
                . $options['format.eol']
        ;
        return $html;
}


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

Examples[edit]

Code Examples[edit]