Files
smarty/docs/fr/designers/language-custom-functions/language-function-html-options.xml
2006-03-22 17:30:04 +00:00

214 lines
5.9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<!-- EN-Revision: 1.13 Maintainer: yannick Status: ready -->
<sect1 id="language.function.html.options">
<title>{html_options}</title>
<para>
{html_options} est une
<link linkend="language.custom.functions">fonction personnalisée</link>
qui crée un groupe d'options avec les données fournies. Elle prend en charge
les éléments sélectionnés par défaut. Les attributs requis sont values et output,
à moins que vous n'utilisiez options à la place.
</para>
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
<colspec colname="type" align="center" />
<colspec colname="required" align="center" />
<colspec colname="default" align="center" />
<colspec colname="desc" />
<thead>
<row>
<entry>Nom attribut</entry>
<entry>Type</entry>
<entry>Requis</entry>
<entry>Defaut</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>values</entry>
<entry>array</entry>
<entry>Oui, à moins que vous n'utilisiez
l'attribut options</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>un tableau de valeurs pour les listes
déroulantes</entry>
</row>
<row>
<entry>output</entry>
<entry>array</entry>
<entry>Oui, à moins que vous n'utilisiez
l'attribut options</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Un tableau de libellés pour la liste
déroulante</entry>
</row>
<row>
<entry>selected</entry>
<entry>chaîne de caractères/tableau</entry>
<entry>Non</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>Les éléments sélectionnés</entry>
</row>
<row>
<entry>options</entry>
<entry>Tableau associatif</entry>
<entry>Oui, à moins que vous n'utilisiez option
et values</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Un tableau associatif valeur / libellé</entry>
</row>
<row>
<entry>name</entry>
<entry>chaîne de caractères</entry>
<entry>Non</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>Nom du goupe d'options</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Si la valeur donnée est un tableau, elle sera traitée comme un
&lt;optgroup&gt; html, et affichée. La récursivité est supportée avec
&lt;optgroup&gt;. La sortie est compatible XHTML.
</para>
<para>
Si l'attribut optionnel <emphasis>name</emphasis> est donné, les
balises &lt;select name="groupname"&gt;&lt;/select&gt; entoureront la
liste d'options. Sinon, seule la liste &lt;option&gt; sera générée.
</para>
<para>
Tous les paramètres qui ne sont pas dans la liste ci-dessus sont
affichés en tant que paires nom / valeur dans la balise &lt;select&gt;. Ils
sont ignorés si le paramètre optionnel <emphasis>name</emphasis>
n'est pas donné.
</para>
<example>
<title>{html_options}</title>
<para>
<emphasis role="bold">Exemple 1 :</emphasis>
</para>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
<para>
Où le template est :
</para>
<programlisting>
<![CDATA[
<select name="customer_id">
{html_options values=$cust_ids output=$cust_names selected=$customer_id}
</select>
]]>
</programlisting>
<para>
<emphasis role="bold">Exemple 2 :</emphasis>
</para>
<programlisting>
<![CDATA[
<?php
$smarty->assign('cust_options', array(
1000 => 'Joe Schmoe',
1001 => 'Jack Smith',
1002 => 'Jane Johnson',
1003 => 'Charlie Brown')
);
$smarty->assign('customer_id', 1001);
?>
]]>
</programlisting>
<para>
Où le template est :
</para>
<programlisting>
<![CDATA[
{html_options name=customer_id options=$cust_options selected=$customer_id}
]]>
</programlisting>
<para>
Les deux exemples afficheront :
</para>
<screen>
<![CDATA[
<select name="customer_id">
<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>
]]>
</screen>
</example>
<example>
<title>{html_options} - Exemple avec une base de données (eg PEAR ou ADODB):</title>
<programlisting role="php">
<![CDATA[
<?php
$sql = 'select type_id, types from contact_types order by type';
$smarty->assign('contact_types',$db->getAssoc($sql));
$sql = 'select contact_id, name, email, contact_type_id
from contacts where contact_id='.$contact_id;
$smarty->assign('contact',$db->getRow($sql));
?>
]]>
</programlisting>
<para>
où le template est :
</para>
<programlisting>
<![CDATA[
<select name="type_id">
<option value='null'>-- none --</option>
{html_options name='contact_type' options=$contact_types selected=$contact.type_id}
</select>
]]>
</programlisting>
</example>
<para>
Voir aussi
<link linkend="language.function.html.checkboxes">{html_checkboxes}</link> et
<link linkend="language.function.html.radios">{html_radios}</link>.
</para>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->