src/Form/RegistrationFormType.php line 15

  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. class RegistrationFormType extends AbstractType
  13. {
  14.     public function buildForm(FormBuilderInterface $builder, array $options): void
  15.     {
  16.         $builder
  17.             ->add('email')
  18.             ->add('plainPassword'PasswordType::class, [
  19.                 // instead of being set onto the object directly,
  20.                 // this is read and encoded in the controller
  21.                 'mapped' => false,
  22.                 'attr' => ['autocomplete' => 'new-password'],
  23.                 'constraints' => [
  24.                     new NotBlank([
  25.                         'message' => 'Veuillez entrer un mot de passe',
  26.                     ]),
  27.                     new Length([
  28.                         'min' => 6,
  29.                         'minMessage' => 'Votre mot de passe doit comporter au moins {{ limit }} caractères',
  30.                         // max length allowed by Symfony for security reasons
  31.                         'max' => 4096,
  32.                     ]),
  33.                 ],
  34.             ])
  35.         ;
  36.     }
  37.     public function configureOptions(OptionsResolver $resolver): void
  38.     {
  39.         $resolver->setDefaults([
  40.             'data_class' => User::class,
  41.         ]);
  42.     }
  43. }