Skip to content

Commit 816cf17

Browse files
committed
[DomCrawler] Fixed incorrect handling of image inputs
1 parent 6a4d765 commit 816cf17

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Symfony/Component/DomCrawler/Form.php

Lines 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

Lines 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)