Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] Ability to clear form errors#5152

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
colinodell wants to merge3 commits intosymfony:masterfromcolinodell:form-clear-errors
Closed
Show file tree
Hide file tree
Changes fromall 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
7 changes: 7 additions & 0 deletionscomponents/form/introduction.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -697,6 +697,13 @@ method to access the list of errors. It returns a
This is useful, for example, if you want to use PHP's ``array_`` function
on the form errors.

Clearing Form Errors
~~~~~~~~~~~~~~~~~~~~

Any errors can be manually cleared using the :method:`Symfony\\Component\\Form\\FormInterface::clearErrors`
method. This is useful when you'd like to validate the form without showing validation errors to the user
(i.e. during a partial AJAX submission or :doc:`dynamic form modification </cookbook/form/dynamic_form_modification>`).

.. _Packagist: https://packagist.org/packages/symfony/form
.. _Twig: http://twig.sensiolabs.org
.. _`Twig Configuration`: http://twig.sensiolabs.org/doc/intro.html
23 changes: 23 additions & 0 deletionscookbook/form/dynamic_form_modification.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,3 +731,26 @@ all of this, use a listener::

By doing this, you may accidentally disable something more than just form
validation, since the ``POST_SUBMIT`` event may have other listeners.

Clearing Form Errors
~~~~~~~~~~~~~~~~~~~~

Alternatively, if you want to perform validation but not show errors to the user
during the AJAX reload, you could instead clear them before rendering the form::

public function createAction(Request $request)
{
$meetup = new SportMeetup();
$form = $this->createForm(new SportMeetupType(), $meetup);
$form->handleRequest($request);
if ($form->isValid()) {
// ... save the meetup, redirect etc.
}

$form->clearErrors(true);

return $this->render(
'AppBundle:Meetup:create.html.twig',
array('form' => $form->createView())
);
}

[8]ページ先頭

©2009-2025 Movatter.jp