Skip to content

Commit

Permalink
bug #9884 [DomCrawler] Fixed creating form objects from named form no…
Browse files Browse the repository at this point in the history
…des (jakzal)

This PR was merged into the 2.3 branch.

Discussion
----------

[DomCrawler] Fixed creating form objects from named form nodes

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9619
| License       | MIT
| Doc PR        | -

Commits
-------

72d6322 [DomCrawler] Fixed creating form objects from form nodes.
  • Loading branch information
fabpot committed Dec 29, 2013
2 parents 20a0fe7 + 72d6322 commit 7fc0a53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -383,7 +383,7 @@ private function initialize()
$root = $document->appendChild($document->createElement('_root'));

// add submitted button if it has a valid name
if ($this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
if ('form' !== $this->button->nodeName && $this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
}

Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/FormTest.php
Expand Up @@ -273,6 +273,16 @@ public function testGetFormNode()
$this->assertSame($dom->getElementsByTagName('form')->item(0), $form->getFormNode(), '->getFormNode() returns the form node associated with this form');
}

public function testGetFormNodeFromNamedForm()
{
$dom = new \DOMDocument();
$dom->loadHTML('<html><form name="my_form"><input type="submit" /></form></html>');

$form = new Form($dom->getElementsByTagName('form')->item(0), 'http://example.com');

$this->assertSame($dom->getElementsByTagName('form')->item(0), $form->getFormNode(), '->getFormNode() returns the form node associated with this form');
}

public function testGetMethod()
{
$form = $this->createForm('<form><input type="submit" /></form>');
Expand Down

0 comments on commit 7fc0a53

Please sign in to comment.