File tree 2 files changed +22
-0
lines changed
src/Symfony/Component/DomCrawler
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,11 @@ public function getUri()
211
211
212
212
protected function getRawUri ()
213
213
{
214
+ // If the form was created from a button rather than the form node, check for HTML5 action overrides
215
+ if ($ this ->button !== $ this ->node && $ this ->button ->getAttribute ('formaction ' )) {
216
+ return $ this ->button ->getAttribute ('formaction ' );
217
+ }
218
+
214
219
return $ this ->node ->getAttribute ('action ' );
215
220
}
216
221
@@ -227,6 +232,11 @@ public function getMethod()
227
232
return $ this ->method ;
228
233
}
229
234
235
+ // If the form was created from a button rather than the form node, check for HTML5 method override
236
+ if ($ this ->button !== $ this ->node && $ this ->button ->getAttribute ('formmethod ' )) {
237
+ return strtoupper ($ this ->button ->getAttribute ('formmethod ' ));
238
+ }
239
+
230
240
return $ this ->node ->getAttribute ('method ' ) ? strtoupper ($ this ->node ->getAttribute ('method ' )) : 'GET ' ;
231
241
}
232
242
Original file line number Diff line number Diff line change @@ -320,6 +320,12 @@ public function testGetMethod()
320
320
$ this ->assertEquals ('PATCH ' , $ form ->getMethod (), '->getMethod() returns the method defined in the constructor if provided ' );
321
321
}
322
322
323
+ public function testGetMethodWithOverride ()
324
+ {
325
+ $ form = $ this ->createForm ('<form method="get"><input type="submit" formmethod="post" /></form> ' );
326
+ $ this ->assertEquals ('POST ' , $ form ->getMethod (), '->getMethod() returns the method attribute value of the form ' );
327
+ }
328
+
323
329
public function testGetSetValue ()
324
330
{
325
331
$ form = $ this ->createForm ('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form> ' );
@@ -527,6 +533,12 @@ public function testGetUriWithoutAction()
527
533
$ this ->assertEquals ('http://localhost/foo/bar ' , $ form ->getUri (), '->getUri() returns path if no action defined ' );
528
534
}
529
535
536
+ public function testGetUriWithActionOverride ()
537
+ {
538
+ $ form = $ this ->createForm ('<form action="/foo"><button type="submit" formaction="/bar" /></form> ' , null , 'http://localhost/foo/ ' );
539
+ $ this ->assertEquals ('http://localhost/bar ' , $ form ->getUri (), '->getUri() returns absolute URIs ' );
540
+ }
541
+
530
542
public function provideGetUriValues ()
531
543
{
532
544
return array (
You can’t perform that action at this time.
0 commit comments