My favorites | Sign in
Project Logo
                
Search
for
Updated Aug 26, 2008 by OpenForce.Auth
ofFormConfirmPlugin__Example  

使用例

1.フォームクラスの作成

確認画面の書き出し処理を、confirmメソッド内で行います。

<?php

class SampleForm extends sfForm
{
  private static $sel = array(
   1=>'A',
   2=>'B'
  );
  public function configure()
  {
    $this->setWidgets(array(
      'title'       => new sfWidgetFormInput(),
      'description' => new sfWidgetFormTextarea(),
      'sel' => new sfWidgetFormSelectMany(array('choices'=>self::$sel)),
      'crypto' => new sfWidgetFormCryptographp(),
      'test' => new sfWidgetFormInputCheckbox()
    ));

    $this->setValidators(array(
      'title'       => new sfValidatorString(array('max_length' => 255, 'required' => true)),
      'description' => new sfValidatorString(array('required' => true)),
	  'crypto'=> new sfValidatorCryptographp(),
      'sel'=> new sfValidatorPass(),
      'test'=> new sfValidatorPass()
    ));  	
  	
  	
  	$this->getWidgetSchema()->setLabels(array(
  	
  		'title'=>'タイトル',
  		'description'=>'詳細',
  		'crypto'=>'認証',
  		'sel'=>'選択',
  		'test'=>'テスト'
  	));
  	
  }
  
  /**
   * 確認画面
   *
   * @return string 確認画面
   */
  public function confirm()
  {
    $conf = new ofFormConfirm($this, array(
      'crypto'
    ));
    return $conf->render();
    
  }
  
}

2.アクション

サンプルではデータベースへの書き込みは省略しています。


class sampleActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfWebRequest $request A request object
  */
  public function executeIndex($request)
  {
  	$this->f = new SampleForm();
  	$this->f->getWidgetSchema()->setNameFormat("sample[%s]");
  	
  	return ofFormConfirmPattern::standard($this->f, $this, "sample");
  	
  }
  
  public function executeUpdate()
  {
  	if(!$data = $this->getUser()->getFlash("sample"))
  	{
  		//多重ポスト防止
  		return sfView::ERROR;
  	}
  	//データ登録処理
  	$this->f = new SampleForm();
  	$this->f->bind($data);
  	
  }
  
}

indexInput.php

<form action="<?php echo url_for($sf_context->getModuleName()."/index") ?>" method="post">
	<table>
		<?php echo $f ?>
	</table>
	<input type="submit" value="送信" />
</form>

indexSuccess.php

<table>
<?php echo $f->confirm() ?>
</table>
<?php echo button_to("登録", $sf_context->getModuleName()."/update") ?>

updateSuccess.php

<p>登録しました</p>
<table>
<?php echo $f->confirm() ?>
</table>

Sign in to add a comment
Hosted by Google Code