Source for file block.form.php

Documentation is available at block.form.php

  1. <?php
  2. /**
  3.  *  smarty block:フォームタグ出力プラグイン
  4.  */
  5. function smarty_block_form($params$content&$smarty&$repeat)
  6. {
  7.     if ($repeat{
  8.         // {form}: ブロック内部に進む前の処理
  9.  
  10.         // 配列指定のフォームヘルパ用カウンタをリセットする
  11.         $c =Ethna_Controller::getInstance();
  12.         $view =$c->getView();
  13.         $view->resetFormCounter();
  14.  
  15.         // {form default=... }
  16.         if (isset($params['default']=== false{
  17.             // 指定なしのときは $form を使う
  18.             // 1テンプレートに複数 {form} を指定する場合は、
  19.             // default を指定することが必要
  20.             $af =$c->getActionForm();
  21.  
  22.             // c.f. http://smarty.net/manual/en/plugins.block.functions.php
  23.             $smarty->_tag_stack[count($smarty->_tag_stack)-1][1]['default']
  24.                 =$af->getArray(false);
  25.         }
  26.  
  27.         // {form name=... }
  28.         // 複数 {form} が置かれた場合に、それぞれを識別する役割を果たす
  29.         if (isset($params['name']=== false{
  30.             // c.f. http://smarty.php.net/manual/en/plugins.block.functions.php
  31.             $smarty->_tag_stack[count($smarty->_tag_stack)-1][1]['name']
  32.                 = 'default';
  33.         }
  34.  
  35.         // 動的フォームヘルパを呼ぶ
  36.         if (isset($params['ethna_action'])) {
  37.             $ethna_action $params['ethna_action'];
  38.             $view =$c->getView();
  39.             $view->addActionFormHelper($ethna_actiontrue);
  40.         }  
  41.  
  42.         // ここで返す値は出力されない
  43.         return '';
  44.  
  45.     else {
  46.         // {/form}: ブロック全体を出力
  47.  
  48.         $c =Ethna_Controller::getInstance();
  49.         $view =$c->getView();
  50.         if ($view === null{
  51.             return null;
  52.         }
  53.  
  54.         // {form ethna_action=... }
  55.         if (isset($params['ethna_action'])) {
  56.             $ethna_action $params['ethna_action'];
  57.             unset($params['ethna_action']);
  58.  
  59.             $view->addActionFormHelper($ethna_action);
  60.             $hidden $c->getActionRequest($ethna_action'hidden');
  61.             $content $hidden $content;
  62.         }
  63.  
  64.         //  {form name=... }
  65.         //  指定された場合は、submitされた {form}を識別する
  66.         //  id をhiddenタグで指定する
  67.         //
  68.         //  $params['name'] は formタグのnameタグになるため
  69.         //  unset してはいけない
  70.         $name $params['name'];
  71.         if ($name != 'default'{
  72.             $name_hidden sprintf('<input type="hidden" name="ethna_fid" value="%s" />',
  73.                                    htmlspecialchars($nameENT_QUOTES)
  74.                            );
  75.             $content $name_hidden $content;
  76.         }
  77.  
  78.         // enctype の略称対応
  79.         if (isset($params['enctype'])) {
  80.             if ($params['enctype'== 'file'
  81.                 || $params['enctype'== 'multipart'{
  82.                 $params['enctype''multipart/form-data';
  83.             else if ($params['enctype'== 'url'{
  84.                 $params['enctype''application/x-www-form-urlencoded';
  85.             }
  86.         }
  87.  
  88.         // defaultはもう不要
  89.         if (isset($params['default'])) {
  90.             unset($params['default']);
  91.         }
  92.  
  93.         // $contentを囲む<form>ブロック全体を出力
  94.         return $view->getFormBlock($content$params);
  95.     }
  96. }

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