I want to set two Text fields in one row in the from class. That they loke like this:
Name/surname ______ _______
I can't find something in the Internet. I use this code in the Form class:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextareaType::class)
->add('surname', TextareaType::class);
}
But this will be shown like this:
Name ____
surname ____
and this is wrong in my situation. Is it possible to do that in the form class? Thanks for your help.
CodePudding user response:
You can show your form_rows in a more custom way by doing this:
Instead of showing your form in the more universal way:
{{ form_start(myForm) }}
{{ form_widget(myForm) }}
{{ form_end(myForm) }}
You can, in fact, do the next:
{{ form_start(myForm) }}
{{ form_row(myForm.field1) }}
{{ form_row(myForm.field2) }}
{{ form_widget(myForm) }}
{{ form_end(myForm) }}
This will allow you to show those rows how you want with extra arguments, and it will continue to show the rest, so you do not need to use form_row
for every row once you have started using it.
Now, you can achieve what you are asking using display: flex, and setting it's direction as row.
Using bootstrap:
{{ form_start(myForm) }}
<div class = "d-flex flex-row">
{{ form_row(myForm.field1) }}
{{ form_row(myForm.field2) }}
</div>
{{ form_widget(myForm) }}
{{ form_end(myForm) }}
Without bootstrap:
{{ form_start(myForm) }}
<div style = "display: flex; flex-direction: row;">
{{ form_row(myForm.field1) }}
{{ form_row(myForm.field2) }}
</div>
{{ form_widget(myForm) }}
{{ form_end(myForm) }}
You can put the label you want only to field1, and so, field 2
, without a label, will appear as you are asking, next to the input field of field 1
.