From 26c72ed383c0eb2cedbe1a4cf3da133784548916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 16 Oct 2017 16:24:37 +0200 Subject: [PATCH] [FrameworkBundle] Added doc for ControllerTrait::isFormValid --- best_practices/forms.rst | 20 ++++++++++++++++++++ forms.rst | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/best_practices/forms.rst b/best_practices/forms.rst index 489979c1862..5efdc80d5a8 100644 --- a/best_practices/forms.rst +++ b/best_practices/forms.rst @@ -197,6 +197,26 @@ Handling a form submit usually follows a similar template: // render the template } +.. versionadded:: 4.1 + The ``ControllerTrait::isFormValid()`` method was added in Symfony 4.1. + + +It's also possible to use a short-cut if the ``ControllerTrait`` is imported: + + +.. code-block:: php + + public function newAction(Request $request) + { + // build the form ... + + if ($this->isFormValid($form)) { + // process the form data + } + + // render the template + } + There are really only two notable things here. First, we recommend that you use a single action for both rendering the form and handling the form submit. For example, you *could* have a ``newAction()`` that *only* renders the form diff --git a/forms.rst b/forms.rst index 5b00a82a3ca..4645a2fb82e 100644 --- a/forms.rst +++ b/forms.rst @@ -259,6 +259,28 @@ your controller:: is called. Otherwise, changes done in the ``*_SUBMIT`` events aren't applied to the view (like validation errors). + +.. versionadded:: 4.1 + The ``ControllerTrait::isFormValid()`` method was added in Symfony 4.1. + + +It's also possible to use a short-cut if the ``ControllerTrait`` is imported: + + +.. code-block:: php + + public function newAction(Request $request) + { + // build the form ... + + if ($this->isFormValid($form)) { + // process the form data + } + + // render the template + } + + This controller follows a common pattern for handling forms and has three possible paths: