开发者

Symfony 1.4 Validation

Can anyone tell me how could i validate the data on the other page (where was not created the form object)?

The thing is: on the page 'A' i am creating the form object with its own validators and showing the form to the user. But the action goes to the page 'B', where i need to validate the data.

I want to do something like this (page 'B'):

$form = new someForm();
$form->bind($this->getRequest()->getParameter('data'));
if($form->isValid()开发者_JAVA技巧)
{
  print 'true';
}
else
{
  print 'false';
}

But as you can imagine, it will print 'false'.


I guess it happens due to CSRF protection of forms in Symfony

Try to use this code

$form = new someForm();
$form->disableLocalCSRFProtection();
$form->bind($this->getRequest()->getParameter('data'));
if($form->isValid())
{
  print 'true';
}
else
{
  print 'false';
}


maybe you could solve this like:

public function executeFoo($request){
  $this->form = new fooForm();
  $this->getUser()->setAttribute('tmpForm', $this->form);
}

in your form the action has to point to module/bar there you can do:

public function executeBar($request){
  $this->forward404Unless($form = $this->getUser()->getAttribute('tmpForm'));
  $form->bind($this->getRequest()->getParameter('data'))
  // and so on
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜