Hackasaurus
Hackasaurus

Reputation: 73

Symfony form widget on new line

I'm rendering a form in Symfony 5.2 and want to put each Textarea input widget box below the label. At the moment it's appearing to the right of the label. I've got a PHP entity with the fields defined as type="text". This is used by the PHP form type:

class InputForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('field1', TextareaType::class)
        ->add('field2', TextareaType::class)
        ->add('save', SubmitType::class)
    ;
}

The controller creates a new form using the entity and calls a twig file, which contains only {{ form(form) }} to render the form.

I assume I need to be doing more in the twig file to customise how the form is rendered and I see that there's a form_widget() function, but I don't see how I can use this to move the widget to the next line. (And I also want to be able to customise the height and width of the widget).

Thanks in advance for any help, I'm happy to elaborate if the above isn't clear. It certainly seems unnecessarily convoluted to me.

Upvotes: 0

Views: 1045

Answers (1)

Tom Tom
Tom Tom

Reputation: 3698

Easiest is just to add a

label { display: block }

rule to your CSS

Else you could override the form theme to add a div container around the label, here, or just change the label element to a div.

Upvotes: 3

Related Questions