0

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.