Skip to content

Commit

Permalink
bug #23254 [Form][TwigBridge] render hidden _method field in form_res…
Browse files Browse the repository at this point in the history
…t() (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()
  • Loading branch information
fabpot committed Jun 21, 2017
2 parents 9a0d342 + 0ee3f57 commit 7cc97b6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Expand Up @@ -262,6 +262,7 @@
{%- endblock form -%}

{%- block form_start -%}
{%- do form.setMethodRendered() -%}
{% set method = method|upper %}
{%- if method in ["GET", "POST"] -%}
{% set form_method = method %}
Expand Down Expand Up @@ -301,6 +302,20 @@
{{- form_row(child) -}}
{% endif %}
{%- 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 %}

{# Support #}
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Bridge/Twig/composer.json
Expand Up @@ -22,7 +22,7 @@
"require-dev": {
"symfony/asset": "~2.7",
"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/intl": "~2.3",
"symfony/routing": "~2.2",
Expand All @@ -36,6 +36,9 @@
"symfony/var-dumper": "~2.7.16|^2.8.9",
"symfony/expression-language": "~2.4"
},
"conflict": {
"symfony/form": "<2.7.30|~2.8,<2.8.23"
},
"suggest": {
"symfony/finder": "",
"symfony/asset": "For using the AssetExtension",
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Form/FormView.php
Expand Up @@ -53,6 +53,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
private $rendered = false;

private $methodRendered = false;

public function __construct(FormView $parent = null)
{
$this->parent = $parent;
Expand Down Expand Up @@ -90,6 +92,19 @@ public function setRendered()
return $this;
}

/**
* @return bool
*/
public function isMethodRendered()
{
return $this->methodRendered;
}

public function setMethodRendered()
{
$this->methodRendered = true;
}

/**
* Returns a child by name (implements \ArrayAccess).
*
Expand Down

0 comments on commit 7cc97b6

Please sign in to comment.