<p dir="auto"><strong>Symfony version(s) affected</strong>: 4.2.6</p>
<p dir="auto"><strong>Description</strong><br>
Rendering form with null block prefix duplicates the form default attributes in rendered html. This is major problem if we'd like to add id attribute to it as id should be unique in whole HTML document.</p>
<p dir="auto"><strong>How to reproduce</strong></p>
<p dir="auto">Create form as follows</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?php

namespace App\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class BugType extends AbstractType
{
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver-&gt;setDefaults([
            'attr' =&gt; [
                'id' =&gt; 'duplicate',
                'foo' =&gt; 'bar',
            ],
        ]);
    }

    public function getBlockPrefix()
    {
        return null;
    }
}"><pre class="notranslate"><span class="pl-ent">&lt;?php</span>

<span class="pl-k">namespace</span> <span class="pl-v">App</span>\<span class="pl-v">Form</span>;

<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">Form</span>\<span class="pl-v">AbstractType</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">OptionsResolver</span>\<span class="pl-v">OptionsResolver</span>;

<span class="pl-k">class</span> <span class="pl-v">BugType</span> <span class="pl-k">extends</span> <span class="pl-v">AbstractType</span>
{
    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">configureOptions</span>(<span class="pl-smi"><span class="pl-smi">OptionsResolver</span></span> <span class="pl-s1"><span class="pl-c1">$</span>resolver</span>)
    {
        <span class="pl-s1"><span class="pl-c1">$</span>resolver</span>-&gt;<span class="pl-en">setDefaults</span>([
            <span class="pl-s">'attr'</span> =&gt; [
                <span class="pl-s">'id'</span> =&gt; <span class="pl-s">'duplicate'</span>,
                <span class="pl-s">'foo'</span> =&gt; <span class="pl-s">'bar'</span>,
            ],
        ]);
    }

    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">getBlockPrefix</span>()
    {
        <span class="pl-k">return</span> <span class="pl-c1">null</span>;
    }
}</pre></div>
<p dir="auto">Pass it to the twig as follows:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?php

namespace App\Controller;

use App\Form\BugType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class IndexController extends AbstractController
{
    /**
     * @Route(&quot;/&quot;, name=&quot;index&quot;)
     */
    public function index()
    {
        $form = $this-&gt;createForm(BugType::class);

        return $this-&gt;render('index/index.html.twig', [
            'form' =&gt; $form-&gt;createView(),
        ]);
    }
}"><pre class="notranslate"><span class="pl-ent">&lt;?php</span>

<span class="pl-k">namespace</span> <span class="pl-v">App</span>\<span class="pl-v">Controller</span>;

<span class="pl-k">use</span> <span class="pl-v">App</span>\<span class="pl-v">Form</span>\<span class="pl-v">BugType</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Bundle</span>\<span class="pl-v">FrameworkBundle</span>\<span class="pl-v">Controller</span>\<span class="pl-v">AbstractController</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">Routing</span>\<span class="pl-v">Annotation</span>\<span class="pl-v">Route</span>;

<span class="pl-k">class</span> <span class="pl-v">IndexController</span> <span class="pl-k">extends</span> <span class="pl-v">AbstractController</span>
{
    <span class="pl-c">/**</span>
<span class="pl-c">     * @Route("/", name="index")</span>
<span class="pl-c">     */</span>
    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">index</span>()
    {
        <span class="pl-s1"><span class="pl-c1">$</span>form</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">createForm</span>(<span class="pl-v">BugType</span>::class);

        <span class="pl-k">return</span> <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">render</span>(<span class="pl-s">'index/index.html.twig'</span>, [
            <span class="pl-s">'form'</span> =&gt; <span class="pl-s1"><span class="pl-c1">$</span>form</span>-&gt;<span class="pl-en">createView</span>(),
        ]);
    }
}</pre></div>
<p dir="auto">And than render it using Twig</p>
<div class="highlight highlight-text-html-twig notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{{ form(form) }}"><pre class="notranslate">{{ form(<span class="pl-smi">form</span>) }}</pre></div>
<p dir="auto">The result will be:</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;form method=&quot;post&quot; id=&quot;duplicate&quot; foo=&quot;bar&quot;&gt;
    &lt;div id=&quot;duplicate&quot; foo=&quot;bar&quot;&gt;
        &lt;input type=&quot;hidden&quot; id=&quot;_token&quot; name=&quot;_token&quot; value=&quot;psSwaT9qr427m_jWqmu7qo1cgbsZ5f-lxcHEcTpeGcY&quot;/&gt;
    &lt;/div&gt;
&lt;/form&gt;"><pre class="notranslate"><span class="pl-kos">&lt;</span><span class="pl-ent">form</span> <span class="pl-c1">method</span>="<span class="pl-s">post</span>" <span class="pl-c1">id</span>="<span class="pl-s">duplicate</span>" <span class="pl-c1">foo</span>="<span class="pl-s">bar</span>"<span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">div</span> <span class="pl-c1">id</span>="<span class="pl-s">duplicate</span>" <span class="pl-c1">foo</span>="<span class="pl-s">bar</span>"<span class="pl-kos">&gt;</span>
        <span class="pl-kos">&lt;</span><span class="pl-ent">input</span> <span class="pl-c1">type</span>="<span class="pl-s">hidden</span>" <span class="pl-c1">id</span>="<span class="pl-s">_token</span>" <span class="pl-c1">name</span>="<span class="pl-s">_token</span>" <span class="pl-c1">value</span>="<span class="pl-s">psSwaT9qr427m_jWqmu7qo1cgbsZ5f-lxcHEcTpeGcY</span>"/&gt;
    <span class="pl-kos">&lt;/</span><span class="pl-ent">div</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">form</span><span class="pl-kos">&gt;</span></pre></div>
<p dir="auto">as you can see form and div have the same attributes.</p>
<p dir="auto">If invalid value submitted the select choice throws an exception <code class="notranslate">TransformationFailedException</code> where radio\checkbox choices set the value to <code class="notranslate">NULL</code>.</p>
<p dir="auto">This behavior cause some problems at validation stage.</p>
<ul dir="auto">
<li>First one is <code class="notranslate">Choice</code> constraint. It do nothing for <code class="notranslate">NULL</code> values.</li>
<li>Next problem more serious. If you dont have <code class="notranslate">NotBlank</code> constraint at the field you will pass validation with <code class="notranslate">NULL</code> value where someone would expect a value from choice set.</li>
</ul>
<p dir="auto">Personally I prefer <code class="notranslate">TransformationFailedException</code> for such cases.</p>