How do I render a form in a controller (not in a template)? I’m looking for something like:
$form = $this->createForm(...
$output = $form->render();
$output would be the html for the form.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The form is merely an object, it doesn’t know what it’s layout is supposed to be — that’s what the template is for. If you’re in a controller extending from the default controller, you can get the HTML of a rendered template like so:
$html = $this->renderView('YourAppBundle:Blah:form.html.twig', array('form' => $form->createView() ) );where that template contains the form markup/rendering code.