Skip to content

Commit

Permalink
bug #34059 [DomCrawler] Skip disabled fields processing in Form (sbogx)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

[DomCrawler] Skip disabled fields processing in Form

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #28179
| License       | MIT

Commits
-------

c73b042 bug #28179 [DomCrawler] Skip disabled fields processing in Form
  • Loading branch information
fabpot committed Feb 3, 2020
2 parents a536342 + c73b042 commit 6c96706
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
10 changes: 1 addition & 9 deletions src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -89,10 +89,6 @@ public function getValues()
{
$values = [];
foreach ($this->fields->all() as $name => $field) {
if ($field->isDisabled()) {
continue;
}

if (!$field instanceof Field\FileFormField && $field->hasValue()) {
$values[$name] = $field->getValue();
}
Expand All @@ -115,10 +111,6 @@ public function getFiles()
$files = [];

foreach ($this->fields->all() as $name => $field) {
if ($field->isDisabled()) {
continue;
}

if ($field instanceof Field\FileFormField) {
$files[$name] = $field->getValue();
}
Expand Down Expand Up @@ -463,7 +455,7 @@ private function initialize()

private function addField(\DOMElement $node)
{
if (!$node->hasAttribute('name') || !$node->getAttribute('name')) {
if (!$node->hasAttribute('name') || !$node->getAttribute('name') || $node->hasAttribute('disabled')) {
return;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/DomCrawler/Tests/FormTest.php
Expand Up @@ -158,12 +158,12 @@ public function testConstructorHandlesFormValues()
public function testMultiValuedFields()
{
$form = $this->createForm('<form>
<input type="text" name="foo[4]" value="foo" disabled="disabled" />
<input type="text" name="foo" value="foo" disabled="disabled" />
<input type="text" name="foo[2]" value="foo" disabled="disabled" />
<input type="text" name="foo[]" value="foo" disabled="disabled" />
<input type="text" name="bar[foo][]" value="foo" disabled="disabled" />
<input type="text" name="bar[foo][foobar]" value="foo" disabled="disabled" />
<input type="text" name="foo[4]" value="foo" />
<input type="text" name="foo" value="foo" />
<input type="text" name="foo[2]" value="foo" />
<input type="text" name="foo[]" value="foo" />
<input type="text" name="bar[foo][]" value="foo" />
<input type="text" name="bar[foo][foobar]" value="foo" />
<input type="submit" />
</form>
');
Expand Down Expand Up @@ -226,10 +226,10 @@ public function provideInitializeValues()
[],
],
[
'takes into account disabled input fields',
'skips disabled input fields',
'<input type="text" name="foo" value="foo" disabled="disabled" />
<input type="submit" />',
['foo' => ['InputFormField', 'foo']],
[],
],
[
'appends the submitted button value',
Expand Down

0 comments on commit 6c96706

Please sign in to comment.