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\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\IsTrue;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.   public function buildForm(FormBuilderInterface $builder, array $options): void
  17.   {
  18.     $builder->add('firstName'TextType::class, [
  19.       'label'=>'Prénom',
  20.       'constraints' => [
  21.         new NotBlank([
  22.           'message' => 'Renseignez un prénom',
  23.         ])
  24.     ]]);
  25.     $builder->add('lastName'TextType::class, [
  26.       'label'=>'Nom',
  27.       'constraints' => [
  28.         new NotBlank([
  29.           'message' => 'Renseignez un nom',
  30.         ])
  31.       ]]);
  32.     $builder->add('email'EmailType::class,[
  33.       'label'=>'Email'
  34.     ]);
  35.     $builder->add('agreeTerms'CheckboxType::class, [
  36.       'label'=>'Accepter les conditions d\'utilisation',
  37.       'mapped' => false,
  38.       'data' => false,
  39.       'constraints' => [
  40.         new IsTrue([
  41.           'message' => 'Vous devez accepter nos conditions d\'utilisation.',
  42.         ]),
  43.       ],
  44.     ]);
  45.     $builder->add('plainPassword'PasswordType::class, [
  46.       // instead of being set onto the object directly,
  47.       // this is read and encoded in the controller
  48.       'label'=>'Mot de passe',
  49.       'mapped' => false,
  50.       'attr' => ['autocomplete' => 'new-password'],
  51.       'constraints' => [
  52.         new NotBlank([
  53.           'message' => 'Renseignez un mote de passe',
  54.         ]),
  55.         new Length([
  56.           'min' => 6,
  57.           'minMessage' => 'Votre mot de passe doit être au moins de {{ limit }} caractères',
  58.           'max' => 4096,
  59.         ]),
  60.       ],
  61.     ]);
  62.   }
  63.   public function configureOptions(OptionsResolver $resolver): void
  64.   {
  65.     $resolver->setDefaults([
  66.       'data_class' => User::class,
  67.     ]);
  68.   }
  69. }