[英]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.问题是:在页面“A”上,我正在使用自己的验证器创建表单 object 并向用户显示表单。 But the action goes to the page 'B', where i need to validate the data.
但是操作转到页面“B”,我需要验证数据。
I want to do something like this (page 'B'):我想做这样的事情(页面'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'.但正如您可以想象的那样,它会打印“假”。
I guess it happens due to CSRF protection of forms in Symfony我猜这是由于 Symfony 中 forms 的 CSRF 保护而发生的
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.