Symfony Form builder: how to organise/group fields into HTML sections from the controller

Viewed 2885

I would like in the form builder controller to say this field belongs to this group then in the view/theme organize all of group1 into div1, group2 into div2, etc..

I tried something like this (creating sub forms) but that is not working; I am not able to display the group

$builder->add(
    $builder->create('group1', FormType::class, array('inherit_data' => true))
        ->add('brand', TextType::class, array(
            'label' => 'brand',
            'invalid_message' => 'Enter a brand',
    ))
);

twig

{{ form_row(form.group1) }}
1 Answers

In case someone else is looking; my error was that I forgot to loop through

{% for row in form.group1 %}
     {{ form_row(row) }}
{% endfor %}
Related