我将表单提交给与输出表单的控制器不同的控制器。
我的问题是如何检查提交的数据是否有效?
我已经尝试了几件事。我要验证的主要内容是“_token”
我该怎么做呢?
这是我的代码示例。
/*
Out put the search form
*/
public function searchAction(Request $request)
{
$form = $this->createFormBuilder()
->setAction($this->generateUrl('email_search')) # <- route to the search process controler
->setMethod('GET')
->add('userSearch', 'text',array(
'required' => true,
'label' => false,
'attr' => array(
'placeholder' => 'Search User Email',
)
)
)
->add('Serch', 'submit')
->getForm();
return $this->render(
'TwigBundle:Search:Search.html.twig',
array(
'form' => $form->createView( )
)
);
}
/*
Process the search
*/
public function emailResultsAction(Request $request){
$form = $this->createFormBuilder()->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$ret = $_POST;
}else{
$ret = 'failed';
}
/*
... Process the search
*/
return new Response(print_r($ret));
}
这给出了错误:
"Call to undefined function Acmy\UserBundle\Controller\getForm() in xxxxxxx"
我可以自己验证搜索,但我不知道如何验证 _token。
Symfony2 文档中似乎没有涵盖这一点。
提前致谢。