-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
(Copied from #6522)
With the current implementation, the attributes passed in the attr option are rendered both in the <form> tag (new) and in the <div>/<table> tag of the form (for BC).
$form = $this->createForm('my_form', $formData, array(
'attr' => array(
'id' => 'foo',
'class' => 'bar',
),
));Template:
{{ form(form) }}
->
<form id="foo" class="bar">
<div id="foo" class="bar">
<!-- rows -->
</div>
</form>Solutions that come to mind:
(a) Move the rendering of the attributes from the <div>/<table> tag to the <form> tag for the root form. This breaks BC because the form_widget() call for the root form does not output the attributes anymore then. Nested forms are not affected.
<form id="foo" class="bar">
<div><!-- no attrs! -->
<!-- rows -->
</div>
</form>(b) Don't render a <div> tag for the root form and do as in (a) for the table layout. This obviously also breaks BC. Nested forms are not affected.
<form id="foo" class="bar">
<!-- rows -->
</form>(c) Don't render any attributes in the <form> tag. Maintains full BC.
<form>
<div id="foo" class="bar">
<!-- rows -->
</div>
</form>Opinions?
While (c) is the best solution from a BC point of view, I think it is rather unintuitive. As a newcomer, if I put a "class" attribute on a form, I would expect it to be on the outermost <form> tag, not on some <div> within.
(a) and (b), on the other hand, break BC for those people that use form_widget() to render the complete form. I don't know how many people would be affected by this, this poll tries to gather some data about that. IMO both (a) and (b) are more intuitive and future-proof.
My favorite is (b) because it removes a useless <div> from the default markup.