src/Form/RegistrationFormType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\DateType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  10. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  11. use Symfony\Component\Form\Extension\Core\Type\TelType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Validator\Constraints\IsTrue;
  15. use Symfony\Component\Validator\Constraints\Length;
  16. use Symfony\Component\Validator\Constraints\NotBlank;
  17. class RegistrationFormType extends AbstractType
  18. {
  19.     public function buildForm(FormBuilderInterface $builder, array $options): void
  20.     {
  21.         $builder
  22.             ->add('role'ChoiceType::class, [
  23.                 'required' => true,
  24.                 'multiple' => false,
  25.                 'expanded' => false,
  26.                 'placeholder' => 'Sélectionner *',
  27.                 'choices'  => [
  28.                     'Je suis chasseur' => 'ROLE_CHASSEUR',
  29.                     'Je suis hôte' => 'ROLE_HOTE',
  30.                     'Je suis les deux' => 'ROLE_HOTE_CHASSEUR'
  31.                 ],
  32.             ])
  33.             ->add('firstName'null, [
  34.                 'attr' => [
  35.                     'class' => 'text-input',
  36.                     'placeholder' => "Prénom *"
  37.                 ]
  38.             ])
  39.             ->add('lastName'null, [
  40.                 'attr' => [
  41.                     'class' => 'text-input',
  42.                     'placeholder' => "Nom *"
  43.                 ]
  44.             ])
  45.             ->add('birthday'DateType::class, [
  46.                 'widget' => 'single_text',
  47.                 'required' => false,
  48.                 // prevents rendering it as type="date", to avoid HTML5 date pickers
  49.                 'html5' => false,
  50.                 // adds a class that can be selected in JavaScript
  51.                 'attr' => [
  52.                     'placeholder' => 'Date de naissance (dd/mm/yyyy)'
  53.                 ],
  54.                 'format' => 'dd/MM/yyyy',
  55.                 'years' => range(date('Y')-100date('Y'))
  56.             ])
  57.             ->add('email'EmailType::class, [
  58.                 'attr' => [
  59.                     'class' => 'email-input',
  60.                     'placeholder' => "Email *"
  61.                 ],
  62.                 'required' => true
  63.             ])
  64.             ->add('phone'TelType::class, [
  65.                 'attr' => [
  66.                     'class' => 'text-input',
  67.                     'placeholder' => "Téléphone *"
  68.                 ]
  69.             ])
  70.             ->add('plainPassword'RepeatedType::class, [
  71.                 // instead of being set onto the object directly,
  72.                 // this is read and encoded in the controller
  73.                 'mapped' => false,
  74.                 'type' => PasswordType::class,
  75.                 'options' => ['attr' => ['autocomplete' => 'new-password']],
  76.                 'constraints' => [
  77.                     new NotBlank([
  78.                         'message' => 'Entrer votre mot de passe svp',
  79.                     ]),
  80.                     new Length([
  81.                         'min' => 6,
  82.                         'minMessage' => 'Votre mot de passe doit avoir au moins {{ limit }} caractères.',
  83.                         // max length allowed by Symfony for security reasons
  84.                         'max' => 4096,
  85.                     ]),
  86.                 ],
  87.             ])
  88.             ->add('isAcceptNewsletter'CheckboxType::class, [
  89.                 'label' => false,
  90.                 'required' => false
  91.             ])
  92.             ->add('agreeCgv'CheckboxType::class, [
  93.                 'mapped' => false,
  94.                 'label' => false,
  95.                 'constraints' => [
  96.                     new IsTrue([
  97.                         'message' => 'Vous devez accepter les conditions générales de vente.',
  98.                     ]),
  99.                 ],
  100.             ])
  101.             ->add('agreeTerms'CheckboxType::class, [
  102.                 'mapped' => false,
  103.                 'label' => false,
  104.                 'constraints' => [
  105.                     new IsTrue([
  106.                         'message' => 'Vous devez accepter les politiques de confidentialités.',
  107.                     ]),
  108.                 ],
  109.             ])
  110.         ;
  111.     }
  112.     public function configureOptions(OptionsResolver $resolver): void
  113.     {
  114.         $resolver->setDefaults([
  115.             'data_class' => User::class,
  116.         ]);
  117.     }
  118. }