Skip to content

Commit 0cd675c

Browse files
committed
bug symfony#25927 [Form] Fixed submitting disabled buttons (HeahDude)
This PR was merged into the 2.7 branch. Discussion ---------- [Form] Fixed submitting disabled buttons | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#23759 | License | MIT | Doc PR | ~ Commits ------- 804b2a1 Fixed submitting disabled buttons
2 parents 1b92f06 + 804b2a1 commit 0cd675c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Symfony/Component/Form/SubmitButton.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public function isClicked()
4343
*/
4444
public function submit($submittedData, $clearMissing = true)
4545
{
46+
if ($this->getConfig()->getDisabled()) {
47+
$this->clicked = false;
48+
49+
return $this;
50+
}
51+
4652
parent::submit($submittedData, $clearMissing);
4753

4854
$this->clicked = null !== $submittedData;

src/Symfony/Component/Form/Tests/CompoundFormTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,28 @@ public function testClickedButtonFromParentForm()
10661066
$this->assertSame($button, $this->form->getClickedButton());
10671067
}
10681068

1069+
public function testDisabledButtonIsNotSubmitted()
1070+
{
1071+
$button = new SubmitButtonBuilder('submit');
1072+
$submit = $button
1073+
->setDisabled(true)
1074+
->getForm();
1075+
1076+
$form = $this->createForm()
1077+
->add($this->getBuilder('text')->getForm())
1078+
->add($submit)
1079+
;
1080+
1081+
$form->submit(array(
1082+
'text' => '',
1083+
'submit' => '',
1084+
));
1085+
1086+
$this->assertTrue($submit->isDisabled());
1087+
$this->assertFalse($submit->isClicked());
1088+
$this->assertFalse($submit->isSubmitted());
1089+
}
1090+
10691091
protected function createForm()
10701092
{
10711093
return $this->getBuilder()

0 commit comments

Comments
 (0)