Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

html_options (Ausgabe von HTML-Options)

{html_options} wird verwendet um HTML-Options Listen mit den übergebenen Daten zu erzeugen. Die Funktion kümmert sich ebenfalls um das setzen des ausgewählten Standardwertes. Die Attribute 'values' und 'output' sind erforderlich, ausser man verwendet das Attribut 'options'.

Attribut Name Typ Erforderlich Standardwert Beschreibung
values array Ja, ausser 'options'-Attribut wird verwendet. n/a Array mit Werten für die dropdown-Liste.
output array Ja, ausser 'options'-Attribut wird verwendet. n/a Arrays mit Namen für die dropdown-Liste.
selected string/array Nein empty Das ausgewählte Array Element.
options associative array Ja, ausser wenn das 'values'- und das 'output'-Attribut verwendet werden. n/a Assoziatives Array mit Werten die ausgegeben werden sollen.

Wenn ein Wert als Array erkannt wird, wird er als HTML-OPTGROUP ausgegeben und die Werte werden in Gruppen dargestellt. Rekursion wird unterstützt. Die Ausgabe ist XHTML kompatibel.

Wenn das (optionale) Attribute name angegeben wurde, wird um die <option>-Liste von <select name="groupname"></select>-Tags umschlossen

Alle Parameter die deren Namen nicht in der obigen Liste genannt wurde, werden dem <select>-Tag als Name/Wert-Paare hinzugefügt. Die Parameter werden ignoriert, wenn kein name-Attribute angegeben wurde.

Example 8.9. html_options

Beispiel 1:


<?php

$smarty->assign('cust_ids', array(1000,1001,1002,1003));
$smarty->assign('cust_names', array(
                              'Joe Schmoe',
                              'Jack Smith',
                              'Jane Johnson',
                              'Charlie Brown'));
$smarty->assign('customer_id', 1001);

?>

  

Wobei das Template wie folgt aussieht:


<select name="customer_id">
   {html_options values=$cust_ids output=$cust_names selected=$customer_id}
</select>

  

Beispiel 2:


<?php

$smarty->assign('cust_options', array(
                                1000 => 'Joe Schmoe',
                                1001 => 'Jack Smith',
                                1002 => 'Jane Johnson',
                                1003 => 'Charlie Brown')
                                );
$smarty->assign('customer_id', 1001);

?>

  

Wobei das Template wie folgt aussieht:


{html_options name=customer_id options=$cust_options selected=$customer_id}

  

Beide Beispiele ergeben folgende Ausgabe:


<select name="customer_id" size="4">
    <option label="Joe Schmoe" value="1000">Joe Schmoe</option>
    <option label="Jack Smith" value="1001" selected="selected">Jack Smith</option>
    <option label="Jane Johnson" value="1002">Jane Johnson</option>
    <option label="Charlie Brown" value="1003">Charlie Brown</option>
</select>

  

Siehe auch {html_checkboxes} und {html_radios}

Example 8.10. {html_options} - Beispiel mit Datenbank (z.B. PEAR oder ADODB):


<?php

$sql = 'select type_id, types from types order by type';
$smarty->assign('types',$db->getAssoc($sql));

$sql = 'select contact_id, name, email, type_id
        from contacts where contact_id='.$contact_id;
$smarty->assign('contact',$db->getRow($sql));

?>

  

Wobei das Template wie folgt aussieht:


<select name="type_id">
    <option value='null'>-- none --</option>
    {html_options name="type" options=$types selected=$contact.type_id}
</select>

  

Siehe auch {html_checkboxes} und {html_radios}

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors