Dmitry
Dmitry

Reputation: 845

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())
{
  print 'true';
}
else
{
  print 'false';
}

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

Upvotes: 0

Views: 912

Answers (2)

Flask
Flask

Reputation: 4996

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
}

Upvotes: 0

Konstantin
Konstantin

Reputation: 25339

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';
}

Upvotes: 1

Related Questions