diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index a127227974..2649d6d33b 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -384,7 +384,24 @@ class Form extends Link implements \ArrayAccess // 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 diff --git a/src/Symfony/Component/DomCrawler/Tests/FormTest.php b/src/Symfony/Component/DomCrawler/Tests/FormTest.php index 843313c4a7..19aab25748 100644 --- a/src/Symfony/Component/DomCrawler/Tests/FormTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/FormTest.php @@ -223,6 +223,11 @@ class FormTest extends \PHPUnit_Framework_TestCase ', array('foobar' => array('InputFormField', 'foobar')), ), + array( + 'turns an image input into x and y fields', + '', + array('bar.x' => array('InputFormField', '0'), 'bar.y' => array('InputFormField', '0')), + ), array( 'returns textareas', '