symfony 可以处理纯 HTML 表单吗? [英] Can symfony handle a plain HTML form?
问题描述
我有一个用纯 HTML 编写的 HTML 表单(即不使用 createFormBuilder
对象),我希望我的控制器以与创建表单相同的方式处理该表单的提交它使用 createFormBuilder
.
我的表单的 path
与控制器中方法的 @route
相同,但我找不到替代
$form->handleRequest($request);如果 ($form->isSubmitted() ) {}
我应该用 symfony 的方式来做吗?
尝试
patch 是您的控制器名称和操作名称
</表单>/*** @Route("/main/patch",name="patch")*/公共功能 patchAction(Request $request){if ($request->getMethod() == Request::METHOD_POST) {$Issn =trim($request->get('issn'));}}
I have a HTML form written in plain HTML (i.e. not using a createFormBuilder
object) and I want my controller to handle the submission of that form in the same way that it would if I had created it using createFormBuilder
.
My form's path
is the same as the @route
for the method in the controller, but I can't find an alternative to
$form->handleRequest($request);
if ($form->isSubmitted() ) {
}
Should I just do it the symfony way?
Try it
patch is a your controller name and the action name
<form class="formSearch" action="{{ path('patch') }}" method="POST">
<input class="inputSearch" type="text" name="issn">
<div class="">
<button class="buttonSerch2" type="submit">serach</button>
</div>
</form>
/**
* @Route("/main/patch",name="patch")
*/
public function patchAction(Request $request)
{
if ($request->getMethod() == Request::METHOD_POST) {
$Issn =trim($request->get('issn'));
}
}
这篇关于symfony 可以处理纯 HTML 表单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!