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

Skip to content

Commit 7cc97b6

Browse files
committed
bug #23254 [Form][TwigBridge] render hidden _method field in form_rest() (xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- [Form][TwigBridge] render hidden _method field in form_rest() | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14261 | License | MIT | Doc PR | Commits ------- 0ee3f57 render hidden _method field in form_rest()
2 parents 9a0d342 + 0ee3f57 commit 7cc97b6

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@
262262
{%- endblock form -%}
263263

264264
{%- block form_start -%}
265+
{%- do form.setMethodRendered() -%}
265266
{% set method = method|upper %}
266267
{%- if method in ["GET", "POST"] -%}
267268
{% set form_method = method %}
@@ -301,6 +302,20 @@
301302
{{- form_row(child) -}}
302303
{% endif %}
303304
{%- endfor %}
305+
306+
{% if not form.methodRendered %}
307+
{%- do form.setMethodRendered() -%}
308+
{% set method = method|upper %}
309+
{%- if method in ["GET", "POST"] -%}
310+
{% set form_method = method %}
311+
{%- else -%}
312+
{% set form_method = "POST" %}
313+
{%- endif -%}
314+
315+
{%- if form_method != method -%}
316+
<input type="hidden" name="_method" value="{{ method }}" />
317+
{%- endif -%}
318+
{% endif %}
304319
{% endblock form_rest %}
305320

306321
{# Support #}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"symfony/asset": "~2.7",
2424
"symfony/finder": "~2.3",
25-
"symfony/form": "~2.7.26|^2.8.19",
25+
"symfony/form": "~2.7.30|^2.8.23",
2626
"symfony/http-kernel": "~2.3",
2727
"symfony/intl": "~2.3",
2828
"symfony/routing": "~2.2",
@@ -36,6 +36,9 @@
3636
"symfony/var-dumper": "~2.7.16|^2.8.9",
3737
"symfony/expression-language": "~2.4"
3838
},
39+
"conflict": {
40+
"symfony/form": "<2.7.30|~2.8,<2.8.23"
41+
},
3942
"suggest": {
4043
"symfony/finder": "",
4144
"symfony/asset": "For using the AssetExtension",

src/Symfony/Component/Form/FormView.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
5353
*/
5454
private $rendered = false;
5555

56+
private $methodRendered = false;
57+
5658
public function __construct(FormView $parent = null)
5759
{
5860
$this->parent = $parent;
@@ -90,6 +92,19 @@ public function setRendered()
9092
return $this;
9193
}
9294

95+
/**
96+
* @return bool
97+
*/
98+
public function isMethodRendered()
99+
{
100+
return $this->methodRendered;
101+
}
102+
103+
public function setMethodRendered()
104+
{
105+
$this->methodRendered = true;
106+
}
107+
93108
/**
94109
* Returns a child by name (implements \ArrayAccess).
95110
*

0 commit comments

Comments
 (0)