src/Form/DemandeInformationType.php line 28

Open in your IDE?
  1. <?php
  2. declare (strict_types 1);
  3. /*
  4.  * Copyright (C) Office National de Publication et de Communication - All Rights Reserved
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited by law
  7.  * This file is proprietary and confidential
  8.  */
  9. namespace App\Form;
  10. use App\Entity\DemandeInformation;
  11. use Symfony\Component\Form\AbstractType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\Validator\Constraints\Email;
  14. use Symfony\Component\Validator\Constraints\Regex;
  15. use Symfony\Component\Validator\Constraints\Length;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. use Symfony\Component\Form\Extension\Core\Type\TelType;
  18. use Symfony\Component\Validator\Constraints\NotEqualTo;
  19. use Symfony\Component\Form\Extension\Core\Type\TextType;
  20. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  21. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  22. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  23. final class DemandeInformationType extends AbstractType
  24. {
  25.     /** @var array */
  26.     private const PROFILS = [
  27.         'Parent' => 'Parent',
  28.         'Elève' => 'Elève',
  29.         'Etudiant(e)' => 'Etudiant',
  30.         'Conseiller(e) d\'orientation' => 'Conseiller d\'orientation',
  31.         'Chef d\'établissement' => 'Chef d\'établissement',
  32.     ];
  33.     /** @var array */
  34.     private const NIVEAUX = [
  35.         'Maternelle' => 'Maternelle',
  36.         'Primaire' => 'Primaire',
  37.         'Collège' => 'Collège',
  38.         'Lycée' => 'Lycée',
  39.         'Professionnel' => 'Professionnel',
  40.         'Post-Bac' => 'Post-Bac',
  41.     ];
  42.     public function buildForm(FormBuilderInterface $builder, array $options): void
  43.     {
  44.         $builder
  45.             ->add('profil'ChoiceType::class, [
  46.                 'choices' => self::PROFILS,
  47.             ])
  48.             ->add('niveau'ChoiceType::class, [
  49.                 'multiple' => true,
  50.                 'expanded' => true,
  51.                 'choices' => self::NIVEAUX,
  52.             ])
  53.             ->add('interlocuteurPrenom'null, [
  54.                 'required' => true,
  55.                 'constraints' => [new Length(['min' => 3'max' => 30])],
  56.             ])
  57.             ->add('interlocuteurNom'null, [
  58.                 'required' => true,
  59.                 'constraints' => [new Length(['min' => 3'max' => 30])],
  60.                 'attr' => ['maxlength' => 30],
  61.             ])
  62.             ->add('adresse'null, ['constraints' => [new Length(['max' => 100])]])
  63.             ->add('cp'null, ['constraints' => [new Length(['max' => 7])]])
  64.             ->add('ville'null, ['constraints' => [new Length(['max' => 30])]])
  65.             ->add('interlocuteurTelephone'TelType::class, [
  66.                 'attr' => [
  67.                     'pattern' => '.*(?<!760463968)$',
  68.                     'title' => 'Le numéro de téléphone est bloqué !',
  69.                     'maxlength' => 30,
  70.                 ],
  71.                 'help' => 'Numéro réservé au rappel par l’établissement',
  72.                 'help_attr' => ['class' => 'help-telephone']
  73.             ])
  74.             ->add('interlocuteurEmail'EmailType::class, [
  75.                     'required' => true,
  76.                     'constraints' => [
  77.                         new Email(),
  78.                         new Regex([
  79.                             'pattern' => '/^(?!Delebarrenicolas|nicolasdelebarre)[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i',
  80.                             'message' => 'Cette adresse email est interdite.'
  81.                         ]),
  82.                     ],
  83.                     'attr' => ['maxlength' => 35],
  84.                 ])
  85.             ->add('commentaires'TextareaType::class,
  86.                 [
  87.                     'required' => true,
  88.                     'constraints' => [new Length(['max' => 500])],
  89.                     'data' => 'Je souhaite recevoir des informations sur cet établissement...',
  90.                     'attr' => [
  91.                         'maxlength' => 500,
  92.                     ],
  93.                 ])
  94.             ->add('autoriseContact'null, ['required' => false])
  95.             /* Honeypot : */
  96.             ->add('email2'TextType::class,
  97.                 [
  98.                     'required' => false,
  99.                     'mapped' => false,
  100.                     'label' => false,
  101.                     'attr' => [
  102.                         'style' => 'display:none !important',
  103.                         'tabindex' => '-1',
  104.                         'autocomplete' => 'off',
  105.                     ],
  106.                 ]);
  107.     }
  108.     public function configureOptions(OptionsResolver $resolver): void
  109.     {
  110.         $resolver->setDefaults([
  111.             'data_class' => DemandeInformation::class,
  112.         ]);
  113.     }
  114. }