diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index 0390e3fc7831..a48769ad5091 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -211,6 +211,11 @@ public function getUri() protected function getRawUri() { + // If the form was created from a button rather than the form node, check for HTML5 action overrides + if ($this->button !== $this->node && $this->button->getAttribute('formaction')) { + return $this->button->getAttribute('formaction'); + } + return $this->node->getAttribute('action'); } @@ -227,6 +232,11 @@ public function getMethod() return $this->method; } + // If the form was created from a button rather than the form node, check for HTML5 method override + if ($this->button !== $this->node && $this->button->getAttribute('formmethod')) { + return strtoupper($this->button->getAttribute('formmethod')); + } + return $this->node->getAttribute('method') ? strtoupper($this->node->getAttribute('method')) : 'GET'; } diff --git a/src/Symfony/Component/DomCrawler/Tests/FormTest.php b/src/Symfony/Component/DomCrawler/Tests/FormTest.php index b052db213463..7546769091db 100644 --- a/src/Symfony/Component/DomCrawler/Tests/FormTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/FormTest.php @@ -320,6 +320,12 @@ public function testGetMethod() $this->assertEquals('PATCH', $form->getMethod(), '->getMethod() returns the method defined in the constructor if provided'); } + public function testGetMethodWithOverride() + { + $form = $this->createForm('
'); + $this->assertEquals('POST', $form->getMethod(), '->getMethod() returns the method attribute value of the form'); + } + public function testGetSetValue() { $form = $this->createForm('
'); @@ -527,6 +533,12 @@ public function testGetUriWithoutAction() $this->assertEquals('http://localhost/foo/bar', $form->getUri(), '->getUri() returns path if no action defined'); } + public function testGetUriWithActionOverride() + { + $form = $this->createForm('