S
S
symnoob2018-04-26 16:43:27
symfony
symnoob, 2018-04-26 16:43:27

Symfony 4 using Form Type and Bootstrap 4 how to use GRID?

Hello, I have a question about Forms in Symphony.
Created Form:
File: register_content.html.twig

{% trans_default_domain 'FOSUserBundle' %}

{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }}
    {{ form_widget(form, {'attr': {'class': 'form-row'}}) }}
    <div>
        <input type="submit" value="{{ 'registration.submit'|trans }}" class="btn btn-primary btn-block" />
    </div>
{{ form_end(form) }}

File: twig.yaml:
form_themes: ['bootstrap_4_layout.html.twig']
File: RegistrationFormType.php
public function buildForm(FormBuilderInterface $builder, array $options)
    {

        $builder
            ->add('sex', ChoiceType::class, array(
                'label_attr' => array(
                    'class' => 'radio-inline'
                ),
                'choices' => array(
                    'form.Mrs' => 'Mrs',
                    'form.Mr' => 'Mr',
                ),
                'multiple' => false, 'expanded' => true,
                'translation_domain' => 'FOSUserBundle',
                'label' => 'form.sex'
            ))
            ->add('firstName', TextType::class, array(
                'label' => 'form.firstName',
                'translation_domain' => 'FOSUserBundle'))
            ->add('lastName', TextType::class, array(
                'label' => 'form.lastName',
                'translation_domain' => 'FOSUserBundle'));
    }

<form name="fos_user_registration_form" method="post" action="/register/" class="fos_user_registration_register">
    <div id="fos_user_registration_form" class="row">
<div class="form-group"><label for="fos_user_registration_form_email" class="form-control-label required">E-Mail-Adresse</label><input type="email" id="fos_user_registration_form_email" name="fos_user_registration_form[email]" required="required" class="form-control" /></div>
итд.......

how can i add a grid? to get something like this <div class="form-group col-sm-6">:
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2018-04-26
@symnoob

Yes, you will need to create your own theme in which to override the form_row widget. See here for details: symfony.com/doc/current/form/form_customization.html
symnoob . There is exactly your case where you need to add a css class: symfony.com/doc/current/form/form_customization.ht...
Then you have two options: symfony.com/doc/current/form/form_customization.ht...
If you need different classes in different places, it's better to just do everything manually: https://symfony.com/doc/ current/form/rendering.htm...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question