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#9908

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
TerjeBr wants to merge2 commits intosymfony:masterfromTerjeBr:clear-form-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
8 changes: 8 additions & 0 deletionscomponents/form.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 </form/dynamic_form_modification>`).


Learn more
----------

Expand Down
23 changes: 23 additions & 0 deletionsform/dynamic_form_modification.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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())
);
}

[8]ページ先頭

©2009-2025 Movatter.jp