diff --git a/components/form.rst b/components/form.rst index e3b8a96689f..d18990528c9 100644 --- a/components/form.rst +++ b/components/form.rst @@ -744,6 +744,14 @@ method to access the list of errors. It returns a // a FormErrorIterator instance representing the form tree structure $errors = $form->getErrors(true, false); +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 `). + + Learn more ---------- diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index bdab83a47e5..b83a20828af 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -613,3 +613,26 @@ field according to the current selection in the ``sport`` field: The major benefit of submitting the whole form to just extract the updated ``position`` field is that no additional server-side code is needed; all the code from above to generate the submitted form can be reused. + +Clearing Form Errors +~~~~~~~~~~~~~~~~~~~~ + +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()) + ); + } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy