Skip to content
Permalink
Browse files

[DomCrawler] Fixed incorrect handling of image inputs

  • Loading branch information...
robbertkl committed Feb 4, 2014
1 parent 6a4d765 commit 816cf179ee32f87b1116b924a09b81b22e53fdeb
Showing with 23 additions and 1 deletion.
  1. +18 −1 src/Symfony/Component/DomCrawler/Form.php
  2. +5 −0 src/Symfony/Component/DomCrawler/Tests/FormTest.php
@@ -384,7 +384,24 @@ private function initialize()
// add submitted button if it has a valid name
if ('form' !== $this->button->nodeName && $this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
if ('input' == $this->button->nodeName && 'image' == $this->button->getAttribute('type')) {
$name = $this->button->getAttribute('name');
$this->button->setAttribute('value', '0');
// temporarily change the name of the input node for the x coordinate
$this->button->setAttribute('name', $name.'.x');
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
// temporarily change the name of the input node for the y coordinate
$this->button->setAttribute('name', $name.'.y');
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
// restore the original name of the input node
$this->button->setAttribute('name', $name);
}
else {
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
}
}
// find form elements corresponding to the current form
@@ -223,6 +223,11 @@ public function provideInitializeValues()
<input type="submit" name="foobar" value="foobar" />',
array('foobar' => array('InputFormField', 'foobar')),
),
array(
'turns an image input into x and y fields',
'<input type="image" name="bar" />',
array('bar.x' => array('InputFormField', '0'), 'bar.y' => array('InputFormField', '0')),
),
array(
'returns textareas',
'<textarea name="foo">foo</textarea>

0 comments on commit 816cf17

Please sign in to comment.
You can’t perform that action at this time.