Presentation
The select tag allows you to get a combo (select/options) easily from an array of objects/values .
Example using Smarty
{select name="field" values=$arData selected=1}
Exemple using PHP
_eTag ('select', array ('name'=>"field", 'values'=>$arData 'selected'=>1));
additional parameters
Specify keys/values
{select name=select values="1=>MySQL;2=>Postgres;3=>SQLite;4=>SQLServer;5=>Oracle"|toarray}
Set the selected item
{select name=select selected=2 values="1=>MySQL;2=>Postgres;3=>SQLite;4=>SQLServer;5=>Oracle"|toarray}
change the text of an empty choice
{select emptyValues="--none--" name=select values="1;2;3;4;5"|toarray}
change the text and the value if the empty choice
{select emptyValues="KO=>--none--" name=select values="1;2;3;4;5"|toarray}
Do not display empty choice
{select emptyShow=false name=select values="1;2;3;4;5"|toarray}
Specify an id different from the name
{select name=select id=somethingelse values="1;2;3;4;5"|toarray}
Use an array of objects and specify keys/values
Here, we have an array of objects with id/caption properties. Let's tell the tag that the id is the value of the option and that caption is its text in the objectMap parameter.
The array of objects is declared as:
$arObjects = array (); $obj = new StdClass (); $obj->id = '1'; $obj->caption = 'text 1'; $arObjects[] = $obj; $obj = new StdClass (); $obj->id = '2'; $obj->caption = 'text 2'; $arObjects[] = $obj; //Let's pass the array to the template using PPO $ppo->arObjects = $arObjects;
{select name=select id=somethingelse values=$ppo->arObjects objectMap="id;caption"}
Extra parameter to add informations to the tag
{select extra='style="background-color: #ccc;"' name=select values="1;2;3;4;5"|toarray}
(Smarty only) Set the return in a variable
It might happen that you need to not display the select and to put the return value of the tag in a variable that you want to use later.
Use the "assign" parameter".
{select name="field" values=$arData assign=variable}
{if $condition}
{$variable}{* display the selection only if $condition *}
{/if}
