【发布时间】:2021-03-09 07:24:33
【问题描述】:
我有简单的 html 表单和控制器来处理它。 注意 我没有在 html.twig 中使用 Symfony 的表单,例如 {{form_start(form)}} ...。所以我想在Controller中处理简单的html表单。
我的请求正文包含在下面
+request: Symfony\Component\HttpFoundation\ParameterBag {#10
#parameters: array:2 [
"name" => "name"
"amount" => "name"
]
}
在 Controller.php 我有 $form
$defaultData = ['message' => 'Type your message here'];
$form = $this->createFormBuilder($defaultData)
->add('name')
->add('amount')
->getForm();
//here I can't handle the request;
$form->handleRequest($request);
// only 'message' is contain
dd($form->getData());
How to Use a Form without a Data Class 从文档中我尝试在不使用 $data = $request->request->get('data') 的情况下处理来自 html 表单的请求
【问题讨论】: