Symfony 5 form not submitted when a list contains a placeholder

I have a form with different lists like this :

 $builder
      ->add('seatsNumber', ChoiceType::class, [
                                                        'placeholder' => 'choose.number.seats.placeholder',
                                                        'choices' => [
                                                                        '1.seat.choice' => 1,
                                                                        '2.seats.choice' => 2,
                                                                        '3.seats.choice' => 3,
                                                                        '4.seats.choice' => 4,
                                                                        '5.seats.choice' => 5,
                                                                        '6.seats.choice' => 6,
                                                                        '7.seats.choice' => 7,
                                                                        '8.seats.choice' => 8,
                                                                        '9.seats.choice' => 9,
                                                                        '10.seats.choice' => 10
                                                                     ],
                                                        'attr' => [
                                                                    'class' => 'select'
                                                                  ],
                                                        'label' => 'seats.number.label',
                                                        'multiple' => false,
                                                        'required' => true
                                                      ]
                 )

This is the generated HTML :

<select id="vehicle_seatsNumber" name="vehicle[seatsNumber]" required="required" class="select form-control" tabindex="-1">
  <option value="" selected="selected">Choose the number of seats</option>
  <option value="1">1 seat</option>
  <option value="2">2 seats</option>
  <option value="3">3 seats</option>
  <option value="4">4 seats</option>
  <option value="5">5 seats</option>
  <option value="6">6 seats</option>
  <option value="7">7 seats</option>
  <option value="8">8 seats</option>
  <option value="9">9 seats</option>
  <option value="10">10 seats</option>
</select>

When I try to submit the form without having select a choice (placeholder is shown), the form isn’t submitted and no one message is shown.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *