render hidden _method field in form_rest()

This commit is contained in:
Christian Flothmann 2017-06-21 18:08:25 +02:00
parent 9a0d342226
commit 0ee3f57533
3 changed files with 34 additions and 1 deletions

View File

@ -262,6 +262,7 @@
{%- endblock form -%} {%- endblock form -%}
{%- block form_start -%} {%- block form_start -%}
{%- do form.setMethodRendered() -%}
{% set method = method|upper %} {% set method = method|upper %}
{%- if method in ["GET", "POST"] -%} {%- if method in ["GET", "POST"] -%}
{% set form_method = method %} {% set form_method = method %}
@ -301,6 +302,20 @@
{{- form_row(child) -}} {{- form_row(child) -}}
{% endif %} {% endif %}
{%- endfor %} {%- endfor %}
{% if not form.methodRendered %}
{%- do form.setMethodRendered() -%}
{% set method = method|upper %}
{%- if method in ["GET", "POST"] -%}
{% set form_method = method %}
{%- else -%}
{% set form_method = "POST" %}
{%- endif -%}
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
{%- endif -%}
{% endif %}
{% endblock form_rest %} {% endblock form_rest %}
{# Support #} {# Support #}

View File

@ -22,7 +22,7 @@
"require-dev": { "require-dev": {
"symfony/asset": "~2.7", "symfony/asset": "~2.7",
"symfony/finder": "~2.3", "symfony/finder": "~2.3",
"symfony/form": "~2.7.26|^2.8.19", "symfony/form": "~2.7.30|^2.8.23",
"symfony/http-kernel": "~2.3", "symfony/http-kernel": "~2.3",
"symfony/intl": "~2.3", "symfony/intl": "~2.3",
"symfony/routing": "~2.2", "symfony/routing": "~2.2",
@ -36,6 +36,9 @@
"symfony/var-dumper": "~2.7.16|^2.8.9", "symfony/var-dumper": "~2.7.16|^2.8.9",
"symfony/expression-language": "~2.4" "symfony/expression-language": "~2.4"
}, },
"conflict": {
"symfony/form": "<2.7.30|~2.8,<2.8.23"
},
"suggest": { "suggest": {
"symfony/finder": "", "symfony/finder": "",
"symfony/asset": "For using the AssetExtension", "symfony/asset": "For using the AssetExtension",

View File

@ -53,6 +53,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/ */
private $rendered = false; private $rendered = false;
private $methodRendered = false;
public function __construct(FormView $parent = null) public function __construct(FormView $parent = null)
{ {
$this->parent = $parent; $this->parent = $parent;
@ -90,6 +92,19 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
return $this; return $this;
} }
/**
* @return bool
*/
public function isMethodRendered()
{
return $this->methodRendered;
}
public function setMethodRendered()
{
$this->methodRendered = true;
}
/** /**
* Returns a child by name (implements \ArrayAccess). * Returns a child by name (implements \ArrayAccess).
* *