From 10817e53bb98f2b9bf9021ceb730a14095fd8485 Mon Sep 17 00:00:00 2001 From: MrYamous Date: Sun, 14 Mar 2021 19:54:20 +0100 Subject: [PATCH] Replace render by new renderForm method in form documentation --- form/direct_submit.rst | 4 +--- form/dynamic_form_modification.rst | 5 +---- form/form_collections.rst | 4 +--- forms.rst | 13 +++++++------ 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/form/direct_submit.rst b/form/direct_submit.rst index 876ad3964b1..0667adf1a36 100644 --- a/form/direct_submit.rst +++ b/form/direct_submit.rst @@ -29,9 +29,7 @@ control over when exactly your form is submitted and what data is passed to it:: } } - return $this->render('task/new.html.twig', [ - 'form' => $form->createView(), - ]); + return $this->renderForm('task/new.html.twig', $form); } .. tip:: diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index 7c52e5f3abd..e0b25e92190 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -534,10 +534,7 @@ your application. Assume that you have a sport meetup creation controller:: // ... save the meetup, redirect etc. } - return $this->render( - 'meetup/create.html.twig', - ['form' => $form->createView()] - ); + return $this->renderForm('meetup/create.html.twig', $form); } // ... diff --git a/form/form_collections.rst b/form/form_collections.rst index 89f079c944d..88c43621286 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -164,9 +164,7 @@ In your controller, you'll create a new form from the ``TaskType``:: // ... do your form processing, like saving the Task and Tag entities } - return $this->render('task/new.html.twig', [ - 'form' => $form->createView(), - ]); + return $this->renderForm('task/new.html.twig', $form); } } diff --git a/forms.rst b/forms.rst index e80ad65da71..d2fd1f998c9 100644 --- a/forms.rst +++ b/forms.rst @@ -277,12 +277,15 @@ to build another object with the visual representation of the form:: $form = $this->createForm(TaskType::class, $task); - return $this->render('task/new.html.twig', [ - 'form' => $form->createView(), - ]); + return $this->renderForm('task/new.html.twig', $form); } } +.. versionadded:: 5.3 + + The ``renderForm`` method was introduced in Symfony 5.3, allowing to + return 422 HTTP status code if an invalid form is submitted. + Then, use some :ref:`form helper functions ` to render the form contents: @@ -405,9 +408,7 @@ written into the form object:: return $this->redirectToRoute('task_success'); } - return $this->render('task/new.html.twig', [ - 'form' => $form->createView(), - ]); + return $this->renderForm('task/new.html.twig', $form); } }