so I have this Symfony Form
which I created, and there are these 3 inputs that are related to each other. I'm trying to align all three of them in the same line to make it looks better. Here's my code: the FormType
<?php
namespace App\Form;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use App\Entity\TypeParking;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TypeParkingType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('libelle')
->add('tempsmax')
->add('jourdebut')
->add('jourfin')
//these three are the fields that I'm trying to put into a single line
->add('jourstravail_jour', TextType::class, ['property_path' => 'jourstravail[jour]'])
->add('jourstravail_debut', TextType::class, ['property_path' => 'jourstravail[debut]'])
->add('jourstravail_fin', TextType::class, ['property_path' => 'jourstravail[fin]'])
->add('Exception_Name', TextType::class, ['property_path' => 'exception[name]'])
->add('Starting_date', TextType::class, ['property_path' => 'exception[datedebut]'])
->add('Ending_date', TextType::class, ['property_path' => 'exception[datefin]'])
->add('Starting_time', TextType::class, ['property_path' => 'exception[heuredebut]'])
->add('Ending_time', TextType::class, ['property_path' => 'exception[heurefin]'])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => TypeParking::class,
]);
}
}
and here's my _form.html.twig file
{{ form_start(form) }}
{{ form_row(form.libelle, { 'label': 'Label' }) }}
{{ form_row(form.tempsmax, { 'label': 'Max Time' }) }}
{{ form_row(form.jourdebut, { 'label': 'Start Date' }) }}
{{ form_row(form.jourfin, { 'label': 'Ending Date' }) }}
<h3>these are the fields</h3>
{{ form_row(form.jourstravail_jour, { 'label': 'Day' }) }}
{{ form_row(form.jourstravail_debut, { 'label': 'start' }) }}
{{ form_row(form.jourstravail_fin, { 'label': 'end' }) }}
<h3>Exception</h3>
{{ form_row(form.Exception_Name, { 'label': 'Exception Name' }) }}
{{ form_row(form.Starting_date, { 'label': 'Starting Date' }) }}
{{ form_row(form.Ending_date, { 'label': 'Ending Date' }) }}
{{ form_row(form.Starting_time, { 'label': 'Starting Time' }) }}
{{ form_row(form.Ending_time, { 'label': 'Ending Time' }) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}
The fields that I'm trying to format are jourstravail_jour
, jourstravail_debut
and jourstravail_fin
Here is an answer based on my comments that seemed to help you, so you can tag your questions as answered.
You can use it "normally", by using form_label()
and form_widget()
(not sure about this one) and wrap them with Bootstrap classes.
Or you can customize the form_row()
behaviour and include your classes in your own form templates.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.