src/Form/RegistrationFormType.php line 17

  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\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\IsTrue;
  11. use Symfony\Component\Validator\Constraints\Length;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. use VictorPrdh\RecaptchaBundle\Form\ReCaptchaType;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         $builder
  19.             ->add('email'EmailType::class, [
  20.                 'label' => 'Adresse email',
  21.                 'attr' => [
  22.                     'placeholder' => 'Adresse email'
  23.                 ]
  24.             ])
  25.             ->add('plainPassword'PasswordType::class, [
  26.                 // instead of being set onto the object directly,
  27.                 // this is read and encoded in the controller
  28.                 'label' => 'Mot de passe',
  29.                 'mapped' => false,
  30.                 'attr' => [
  31.                     'autocomplete' => 'new-password',
  32.                     'placeholder' => 'Mot de passe'
  33.                 ],
  34.                 'constraints' => [
  35.                     new NotBlank([
  36.                         'message' => 'Veuillez saisir un mot de passe',
  37.                     ]),
  38.                     new Length([
  39.                         'min' => 6,
  40.                         'minMessage' => 'Votre mot de passe doit contenir au moins {{ limit }} caractères',
  41.                         // max length allowed by Symfony for security reasons
  42.                         'max' => 4096,
  43.                     ]),
  44.                 ],
  45.             ])
  46.             ->add('agreeTerms'CheckboxType::class, [
  47.                 'mapped' => false,
  48.                 'constraints' => [
  49.                     new IsTrue([
  50.                         'message' => 'Vous devez accepter les termes & conditions',
  51.                     ]),
  52.                 ],
  53.                 'label' => 'J\'ai lu et j\'accèpte les termes & conditions'
  54.             ])
  55.             ->add('reCaptcha'ReCaptchaType::class)
  56.         ;
  57.     }
  58.     public function configureOptions(OptionsResolver $resolver): void
  59.     {
  60.         $resolver->setDefaults([
  61.             'data_class' => User::class,
  62.         ]);
  63.     }
  64. }