diff --git a/best_practices/forms.rst b/best_practices/forms.rst index 31ffa4d5707..0c61541af84 100644 --- a/best_practices/forms.rst +++ b/best_practices/forms.rst @@ -218,4 +218,21 @@ handling the form submit. For example, you *could* have a ``new()`` action that submit. Both those actions will be almost identical. So it's much simpler to let ``new()`` handle everything. +.. versionadded:: 4.3 + + The ``AbstractController::isFormValid()`` method was added in Symfony 4.3. + +It's also possible to use a short-cut if your controller extends ``AbstractController``:: + + public function new(Request $request) + { + // build the form ... + + if ($this->isFormValid($form, $request)) { + // process the form data + } + + // render the template + } + Next: :doc:`/best_practices/i18n` diff --git a/forms.rst b/forms.rst index bf0d787782d..822d5675020 100644 --- a/forms.rst +++ b/forms.rst @@ -264,6 +264,25 @@ your controller:: is called. Otherwise, changes done in the ``*_SUBMIT`` events aren't applied to the view (like validation errors). + +.. versionadded:: 4.3 + + The ``AbstractController::isFormValid()`` method was added in Symfony 4.3. + +It's also possible to use a short-cut if your controller extends ``AbstractController``:: + + public function new(Request $request) + { + // build the form ... + + if ($this->isFormValid($form, $request)) { + // process the form data + } + + // render the template + } + + This controller follows a common pattern for handling forms and has three possible paths: