src/Form/RegistrationFormType.php line 17

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