Source for file function.select.php

Documentation is available at function.select.php

  1. <?php
  2. /**
  3.  *  smarty function:セレクトフィールド生成
  4.  *
  5.  *  sample:
  6.  *  <code>
  7.  *  $smarty->assign('hoge',
  8.  *                   array(
  9.  *                       '1' => array('name' => 'foo'),
  10.  *                       '2' => array('name' => 'bar')
  11.  *                   )
  12.  *  );
  13.  *  {select list=$hoge name="hoge" value="1" empty="-- please select --"}
  14.  *  </code>
  15.  *  <code>
  16.  *  <select name="hoge">
  17.  *    <option value="">-- please select --</option>
  18.  *    <option value="1" selected="selected">foo</option>
  19.  *    <option value="2">bar</option>
  20.  *  </select>
  21.  *  </code>
  22.  *
  23.  *  @param  array   $list   選択肢一覧
  24.  *  @param  string  $name   フォーム項目名
  25.  *  @param  string  $value  セレクトボックスに渡されたフォーム値
  26.  *  @param  string  $empty  空エントリ(「---選択して下さい---」等)
  27.  *  @deprecated
  28.  */
  29. function smarty_function_select($params&$smarty)
  30. {
  31.     extract($params);
  32.  
  33.     //  empty="...." を加えると、無条件に追加される
  34.     //  ない場合は追加されない
  35.     print "<select name=\"$name\">\n";
  36.     if ($empty{
  37.         printf("<option value=\"\">%s</option>\n"$empty);
  38.     }
  39.     foreach ($list as $id => $elt{
  40.         //    標準に合わせる
  41.         //    @see http://www.w3.org/TR/html401/interact/forms.html#adef-selected
  42.         //    @see http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd
  43.         //    @see http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd
  44.         //    @see http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-frameset.dtd
  45.         //    @see http://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_sformsmodule
  46.         printf("<option value=\"%s\" %s>%s</option>\n",
  47.                $id$id == $value 'selected="selected"' ''$elt['name']);
  48.     }
  49.     print "</select>\n";
  50. }

Documentation generated on Fri, 11 Nov 2011 03:58:10 +0900 by phpDocumentor 1.4.3