symfony バリデーションエラー csrf token: Required.

下記エラー発生。3日程ハマった。
[code]
csrf token: Required.
[/code]

基本的には、バインド (sfForm::bind) の使用の仕方を理解していなかった。
formクラスに下記の要素名定義を行っていなかった為にバインドがうまく行かずに、バリデーションエラーとなっていた。

アクションクラス
[php]
class HogeAction extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
//フォーム生成
$this->form = new HogeForm();
if($request->isMethod(sfRequest::POST))
{
$this->form->bind($request->getParameter(‘hoge’));
if($this->form->isValid())
{
$hoges = $this->form->getValues();
$hoge = $hoges[‘hoge’];
//
$this->getUser()->setFlash(‘hoge’, $hoge);
$this->redirect(‘next/foo’);
}
}
}
[/php]

フォームクラス
[php]
class HogeForm extends BaseForm
{
public function configure()
{
//フォーム設定
$this->setWidgets(array(‘hoge’=> new sfWidgetFormInput()));
//バリデーション設定
$this->setValidators(array(‘hoge’=> new sfValidatorString()));
//要素名定義
$this->widgetSchema->setNameFormat(‘hoge[%s]’);
}
}
[/php]

This entry was posted in php, symfony, 技術情報. Bookmark the permalink.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です