src/Form/SearchType.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Villes;
  4. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  8. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  9. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  13. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  14. use Symfony\Component\Form\Extension\Core\Type\DateType;
  15. class SearchType extends AbstractType
  16. {
  17.     /**
  18.      * @param FormBuilderInterface $builder
  19.      * @param array $options
  20.      */
  21.     public function buildForm(FormBuilderInterface $builder, array $options)
  22.     {
  23.         $builder
  24.             ->add('ville'ChoiceType::class, [
  25.                 'choices' => [
  26.                     'Tunis' => 'Tunis',
  27.                     'Hammamet' => 'Hammamet',
  28.                     'Sousse' => 'Sousse',
  29.                     'Monastir' => 'Monastir',
  30.                     'Mahdia' => 'Mahdia',
  31.                     'Tabarka' => 'Tabarka',
  32.                     'Ain Draham' => 'Ain Draham',
  33.                     'Tozeur' => 'Tozeur',
  34.                     'Djerba' => 'Djerba',
  35.                 ],
  36.                 'placeholder' => 'Choisir votre destination',
  37.                 'required' => false// Permet à l'utilisateur de ne pas spécifier la destination
  38.             ])
  39.             ->add('dateDepart'DateType::class, [
  40.                 'widget' => 'single_text',
  41.                 'required' => true,
  42.                 'attr' => [
  43.                     'class' => 'form-control',
  44.                     'data-custom-attribute' => 'form-control',
  45.                 ],
  46.             ])
  47.             ->add('nombreNuits'null, [
  48.                 'attr' => ['readonly' => true], // le champ est en lecture seule
  49.             ])
  50.             ->add('dateArrive'DateType::class, [
  51.                 'widget' => 'single_text',
  52.                 'required' => true,
  53.                 'attr' => [
  54.                     'class' => 'form-control',
  55.                     'data-custom-attribute' => 'form-control',
  56.                 ],
  57.             ])
  58.             ->add('rooms'CollectionType::class, [
  59.                 'entry_type' => RoomsType::class, // Assuming RoomType is another form type for a single room
  60.                 'allow_add' => true,
  61.                 'allow_delete' => true,
  62.                 'by_reference' => false,
  63.                 'label' => false
  64.             ])
  65.         ;
  66.     }
  67.     /**
  68.      * @param OptionsResolverInterface $resolver
  69.      */
  70.     public function setDefaultOptions(OptionsResolverInterface $resolver)
  71.     {
  72.         $resolver->setDefaults(array(
  73.             'data_class' => 'App\Entity\Search'
  74.         ));
  75.     }
  76. }