Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Added doc for ControllerTrait::isFormValid #8518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions best_practices/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down