8000 Call isSubmitted() before calling isValid() · matthieu88160/symfony-docs@995e2d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 995e2d9

Browse files
ycerutowouterj
authored andcommitted
Call isSubmitted() before calling isValid()
1 parent 5f004c3 commit 995e2d9

File tree

10 files changed

+13
-13
lines changed

10 files changed

+13
-13
lines changed

components/form.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ method:
547547
548548
$form->handleRequest($request);
549549
550-
if ($form->isValid()) {
550+
if ($form->isSubmitted() && $form->isValid()) {
551551
$data = $form->getData();
552552
553553
// ... perform some action, such as saving the data to the database
@@ -573,7 +573,7 @@ method:
573573
574574
$form->handleRequest($request);
575575
576-
if ($form->isValid()) {
576+
if ($form->isSubmitted() && $form->isValid()) {
577577
$data = $form->getData();
578578
579579
// ... perform some action, such as saving the data to the database

controller.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ For example, imagine you're processing a :doc:`form </forms>` submission::
391391
{
392392
// ...
393393

394-
if ($form->isValid()) {
394+
if ($form->isSubmitted() && $form->isValid()) {
395395
// do some sort of processing
396396

397397
$this->addFlash(

controller/upload_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Now you're ready to use this service in the controller::
297297
{
298298
// ...
299299

300-
if ($form->isValid()) {
300+
if ($form->isSubmitted() && $form->isValid()) {
301301
$file = $product->getBrochure();
302302
$fileName = $this->get('app.brochure_uploader')->upload($file);
303303

form/direct_submit.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ submissions::
2222

2323
$form->handleRequest($request);
2424

25-
if ($form->isValid()) {
25+
if ($form->isSubmitted() && $form->isValid()) {
2626
// perform some action...
2727

2828
return $this->redirectToRoute('task_success');
@@ -63,7 +63,7 @@ method, pass the submitted data directly to
6363
if ($request->isMethod('POST')) {
6464
$form->submit($request->request->get($form->getName()));
6565

66-
if ($form->isValid()) {
66+
if ($form->isSubmitted() && $form->isValid()) {
6767
// perform some action...
6868

6969
return $this->redirectToRoute('task_success');
@@ -115,7 +115,7 @@ a convenient shortcut to the previous example::
115115
if 8000 ($request->isMethod('POST')) {
116116
$form->submit($request);
117117

118-
if ($form->isValid()) {
118+
if ($form->isSubmitted() && $form->isValid()) {
119119
// perform some action...
120120

121121
return $this->redirectToRoute('task_success');

form/dynamic_form_modification.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ your application. Assume that you have a sport meetup creation controller::
605605
$meetup = new SportMeetup();
606606
$form = $this->createForm(new SportMeetupType(), $meetup);
607607
$form->handleRequest($request);
608-
if ($form->isValid()) {
608+
if ($form->isSubmitted() && $form->isValid()) {
609609
// ... save the meetup, redirect etc.
610610
}
611611

form/form_collections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ In your controller, you'll now initialize a new instance of ``TaskType``::
178178

179179
$form->handleRequest($request);
180180

181-
if ($form->isValid()) {
181+
if ($form->isSubmitted() && $form->isValid()) {
182182
// ... maybe do some form processing, like saving the Task and Tag objects
183183
}
184184

form/multiple_buttons.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ In your controller, use the button's
2222
:method:`Symfony\\Component\\Form\\ClickableInterface::isClicked` method for
2323
querying if the "Save and add" button was clicked::
2424

25-
if ($form->isValid()) {
25+
if ($form->isSubmitted() && $form->isValid()) {
2626
// ... perform some action, such as saving the task to the database
2727

2828
$nextAction = $form->get('saveAndAdd')->isClicked()

form/without_class.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ an array of the submitted data. This is actually really easy::
2727

2828
$form->handleRequest($request);
2929

30-
if ($form->isValid()) {
30+
if ($form->isSubmitted() && $form->isValid()) {
3131
// data is an array with "name", "email", and "message" keys
3232
$data = $form->getData();
3333
}

reference/forms/types/file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ be used to move the ``attachment`` file to a permanent location::
4747
{
4848
// ...
4949

50-
if ($form->isValid()) {
50+
if ($form->isSubmitted() && $form->isValid()) {
5151
$someNewFilename = ...
5252

5353
$form['attachment']->getData()->move($dir, $someNewFilename);

security/acl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Creating an ACL and Adding an ACE
132132
133133
// ... setup $form, and submit data
134134
135-
if ($form->isValid()) {
135+
if ($form->isSubmitted() && $form->isValid()) {
136136
$entityManager = $this->getDoctrine()->getManager();
137137
$entityManager->persist($comment);
138138
$entityManager->flush();

0 commit comments

Comments
 (0)
0