Skip to content

Commit

Permalink
feature #16029 [FrameworkBundle][TwigBridge] do not render empty form…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
fabpot committed Sep 30, 2015
2 parents 62a0ecd + 1307043 commit dbb099d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ protected function tearDown()
$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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ public function testIsChoiceSelected($expected, $choice, $value)
$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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ protected function tearDown()
$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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ?>
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ protected function tearDown()
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dbb099d

Please sign in to comment.