5

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.

1 Answer 1

8

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.

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

1 Comment

That's what I ended up doing but thought there might be another way. Thanks!

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.