Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DomCrawler] Fixed incorrect handling of image inputs #10205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Symfony/Component/DomCrawler/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down