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

Appearance settings

Commit e453c45

Browse filesBrowse files
committed
bug #10205 [DomCrawler] Fixed incorrect handling of image inputs (robbertkl)
This PR was merged into the 2.3 branch. Discussion ---------- [DomCrawler] Fixed incorrect handling of image inputs | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10204 | License | MIT | Doc PR | A possible approach to fix #10204, but I'm open to suggestions to fix this another way, as this might not be the most 'elegant' way. Initially, my thoughts were to create a new DomCrawler\Field\FormField subclass, especially for image inputs. However, this does not solve the problem, because such a FormField would still exist under 1 name in the FormFieldRegistry. Instead, I've changed it to have 2 separate FormFields instead (which both reference the same input node), with different names (.x and .y) so that both values can be set separately and will both be submitted. Commits ------- 816cf17 [DomCrawler] Fixed incorrect handling of image inputs
2 parents 6a4d765 + 816cf17 commit e453c45
Copy full SHA for e453c45

File tree

Expand file treeCollapse file tree

2 files changed

+23
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-1
lines changed

‎src/Symfony/Component/DomCrawler/Form.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Form.php
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,24 @@ private function initialize()
384384

385385
// add submitted button if it has a valid name
386386
if ('form' !== $this->button->nodeName && $this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
387-
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
387+
if ('input' == $this->button->nodeName && 'image' == $this->button->getAttribute('type')) {
388+
$name = $this->button->getAttribute('name');
389+
$this->button->setAttribute('value', '0');
390+
391+
// temporarily change the name of the input node for the x coordinate
392+
$this->button->setAttribute('name', $name.'.x');
393+
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
394+
395+
// temporarily change the name of the input node for the y coordinate
396+
$this->button->setAttribute('name', $name.'.y');
397+
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
398+
399+
// restore the original name of the input node
400+
$this->button->setAttribute('name', $name);
401+
}
402+
else {
403+
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
404+
}
388405
}
389406

390407
// find form elements corresponding to the current form

‎src/Symfony/Component/DomCrawler/Tests/FormTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Tests/FormTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ public function provideInitializeValues()
223223
<input type="submit" name="foobar" value="foobar" />',
224224
array('foobar' => array('InputFormField', 'foobar')),
225225
),
226+
array(
227+
'turns an image input into x and y fields',
228+
'<input type="image" name="bar" />',
229+
array('bar.x' => array('InputFormField', '0'), 'bar.y' => array('InputFormField', '0')),
230+
),
226231
array(
227232
'returns textareas',
228233
'<textarea name="foo">foo</textarea>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.