feature #16029 [FrameworkBundle][TwigBridge] do not render empty form action attributes (xabbuh)

This PR was merged into the 2.8 branch.

Discussion
----------

[FrameworkBundle][TwigBridge] do not render empty form action attributes

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #13852, #15995
| License       | MIT
| Doc PR        |

Commits
-------

1307043 do not render empty form action attributes
This commit is contained in:
Fabien Potencier 2015-09-30 22:57:05 +02:00
commit dbb099dad6
7 changed files with 62 additions and 2 deletions

View File

@ -274,7 +274,7 @@
{%- else -%}
{% set form_method = "POST" %}
{%- endif -%}
<form name="{{ name }}" method="{{ form_method|lower }}" action="{{ action }}"{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
<form name="{{ name }}" method="{{ form_method|lower }}"{% if action %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
{%- endif -%}

View File

@ -62,6 +62,18 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
$this->extension = null;
}
public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get">', $html);
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

View File

@ -141,6 +141,18 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
}
public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get">', $html);
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

View File

@ -63,6 +63,18 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
$this->extension = null;
}
public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get">', $html);
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

View File

@ -1,6 +1,6 @@
<?php $method = strtoupper($method) ?>
<?php $form_method = $method === 'GET' || $method === 'POST' ? $method : 'POST' ?>
<form name="<?php echo $name ?>" method="<?php echo strtolower($form_method) ?>" action="<?php echo $action ?>"<?php foreach ($attr as $k => $v) { printf(' %s="%s"', $view->escape($k), $view->escape($v)); } ?><?php if ($multipart): ?> enctype="multipart/form-data"<?php endif ?>>
<form name="<?php echo $name ?>" method="<?php echo strtolower($form_method) ?>"<?php if ($action): ?> action="<?php echo $action ?>"<?php endif ?><?php foreach ($attr as $k => $v) { printf(' %s="%s"', $view->escape($k), $view->escape($v)); } ?><?php if ($multipart): ?> enctype="multipart/form-data"<?php endif ?>>
<?php if ($form_method !== $method): ?>
<input type="hidden" name="_method" value="<?php echo $method ?>" />
<?php endif ?>

View File

@ -61,6 +61,18 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
parent::tearDown();
}
public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get">', $html);
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->engine->get('form')->form($view, $vars);

View File

@ -31,6 +31,18 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest
'choice_attr',
);
public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
'method' => 'get',
'action' => '',
));
$html = $this->renderStart($form->createView());
$this->assertSame('<form name="form" method="get">', $html);
}
protected function getExtensions()
{
// should be moved to the Form component once absolute file paths are supported