Reputation: 935
What is the best practice if I want to use multiple forms in one page/controller?
Right now I have multiple actions and I'm including them in twig, but I don't think this is good solution.
Thanks
Upvotes: 0
Views: 1990
Reputation: 4265
Assuming you actually want different, separate forms in your page, you can create many forms in your controller and pass them to Twig, e.g.:
public function mypageAction()
{
$userForm = $this->createForm(UserForm::class, new User);
$companyForm = $this->createForm(CompanyForm::class, new Company);
return $this->render('mypage.html.twig', [
'userForm' => $userForm,
'companyForm' => $companyForm,
]);
}
Of course handling submissions will require separate actions, one for each form.
Upvotes: 3