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

Documentation generated on Fri, 11 Nov 2011 03:57:42 +0900 by phpDocumentor 1.4.3