diff --git a/components/form.rst b/components/form.rst index 7c12ef1159e..29ae4438d3d 100644 --- a/components/form.rst +++ b/components/form.rst @@ -547,7 +547,7 @@ method: $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); // ... perform some action, such as saving the data to the database @@ -573,7 +573,7 @@ method: $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); // ... perform some action, such as saving the data to the database diff --git a/controller.rst b/controller.rst index 89242365c76..6a720c3b007 100644 --- a/controller.rst +++ b/controller.rst @@ -391,7 +391,7 @@ For example, imagine you're processing a :doc:`form ` submission:: { // ... - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { // do some sort of processing $this->addFlash( diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 0d2686c7ae5..6206b92d953 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -297,7 +297,7 @@ Now you're ready to use this service in the controller:: { // ... - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $file = $product->getBrochure(); $fileName = $this->get('app.brochure_uploader')->upload($file); diff --git a/form/direct_submit.rst b/form/direct_submit.rst index 46b4ebb4b1b..6b7fd2a41a8 100644 --- a/form/direct_submit.rst +++ b/form/direct_submit.rst @@ -22,7 +22,7 @@ submissions:: $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { // perform some action... return $this->redirectToRoute('task_success'); @@ -63,7 +63,7 @@ method, pass the submitted data directly to if ($request->isMethod('POST')) { $form->submit($request->request->get($form->getName())); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { // perform some action... return $this->redirectToRoute('task_success'); @@ -115,7 +115,7 @@ a convenient shortcut to the previous example:: if ($request->isMethod('POST')) { $form->submit($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { // perform some action... return $this->redirectToRoute('task_success'); diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index cacacc993e2..8595bb0c1d5 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -605,7 +605,7 @@ your application. Assume that you have a sport meetup creation controller:: $meetup = new SportMeetup(); $form = $this->createForm(new SportMeetupType(), $meetup); $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { // ... save the meetup, redirect etc. } diff --git a/form/form_collections.rst b/form/form_collections.rst index fcabc93d049..3b04bc356d7 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -178,7 +178,7 @@ In your controller, you'll now initialize a new instance of ``TaskType``:: $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { // ... maybe do some form processing, like saving the Task and Tag objects } diff --git a/form/multiple_buttons.rst b/form/multiple_buttons.rst index 8baac65f18f..9c70458a954 100644 --- a/form/multiple_buttons.rst +++ b/form/multiple_buttons.rst @@ -22,7 +22,7 @@ In your controller, use the button's :method:`Symfony\\Component\\Form\\ClickableInterface::isClicked` method for querying if the "Save and add" button was clicked:: - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { // ... perform some action, such as saving the task to the database $nextAction = $form->get('saveAndAdd')->isClicked() diff --git a/form/without_class.rst b/form/without_class.rst index 3f2e99b7851..091ca7f229c 100644 --- a/form/without_class.rst +++ b/form/without_class.rst @@ -27,7 +27,7 @@ an array of the submitted data. This is actually really easy:: $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { // data is an array with "name", "email", and "message" keys $data = $form->getData(); } diff --git a/reference/forms/types/file.rst b/reference/forms/types/file.rst index a0beb43609a..0a9fe2e249c 100644 --- a/reference/forms/types/file.rst +++ b/reference/forms/types/file.rst @@ -47,7 +47,7 @@ be used to move the ``attachment`` file to a permanent location:: { // ... - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $someNewFilename = ... $form['attachment']->getData()->move($dir, $someNewFilename); diff --git a/security/acl.rst b/security/acl.rst index 29eaa5acab7..aa333f109ac 100644 --- a/security/acl.rst +++ b/security/acl.rst @@ -132,7 +132,7 @@ Creating an ACL and Adding an ACE // ... setup $form, and submit data - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($comment); $entityManager->flush();