Closed
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.3.6 |
When the user uses Chrome Inspect feature and changes the <input type="text"
name to include an extra array (e.g. from article_form[title]
to article_form[title][foobar]
, the form fails to render. The reason is that the template is trying to render the "invalid" array as an <input>
value.
Twig_Error_Runtime:
An exception has been thrown during the rendering of a template ("Notice: Array to string conversion").
at vendor\symfony\symfony\src\Symfony\Bridge\Twig\Resources\views\Form\form_div_layout.html.twig:13
at Twig_Template->displayBlock('form_widget_simple', array('value' => array('foo' => 'aa'), 'attr' => array(), 'form' => object(FormView), 'id' => 'article_form_title', 'name' => 'title', 'full_name' => 'article_form[title]', 'disabled' => false, 'label' => 'Article title', 'label_format' => null, 'multipart' => false, 'block_prefixes' => array('form', 'text', '_article_form_title'), 'unique_block_prefix' => '_article_form_title', 'translation_domain' => null, 'cache_key' => '_article_form_title_text', 'errors' => object(FormErrorIterator), 'valid' => false, 'data' => array('foo' => 'aa'), 'required' => true, 'size' => null, 'label_attr' => array(), 'compound' => false, 'method' => 'POST', 'action' => '', 'submitted' => true, 'app' => object(AppVariable)), array('form_widget' => array(object(__TwigTemplate_74fc98e978cb4218b308d1fa4d08196af014f2b1069a5f65da3ed6ecc38bdf83), 'block_form_widget'),
...
The problematic line in the template is this:
The simplest repro-case I managed to create is this one:
public function createAction()
{
$form = $this->createFormBuilder(
[
'title' => [
'foo' => 'bar',
],
])
->add('title', TextType::class)
->getForm();
return $this->render('article/add-article.html.twig', [
'form' => $form->createView(),
]);
}
# article/add-article.html.twig
{% block body %}
{{ form(form) }}
{% endblock %}