src/Form/RegistrationFormType.php line 26

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 Symfony\Component\Form\Extension\Core\Type\FileType;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  15. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  16. use Symfony\Component\Form\Extension\Core\Type\DateType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextType;
  19. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  20. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  21. class RegistrationFormType extends AbstractType
  22. {
  23.     public function buildForm(FormBuilderInterface $builder, array $options): void
  24.     {
  25.         $builder
  26.         ->add('email'EmailType::class, array('required' => false'label' => false))
  27.         ->add('nom'TextType::class, array('required' => false'label' => false))
  28.         ->add('prenom'TextType::class, array('required' => false'label' => false))
  29.         ->add('telephone'TextType::class, array('required' => false'label' => false))
  30.         
  31.             ->add('agreeTerms'CheckboxType::class, [
  32.                 'mapped' => false,
  33.                 'label' => false,
  34.                 'constraints' => [
  35.                     new IsTrue([
  36.                         'message' => 'You should agree to our terms.',
  37.                     ]),
  38.                 ],
  39.             ])
  40.             ->add('plainPassword'PasswordType::class, [
  41.                 // instead of being set onto the object directly,
  42.                 // this is read and encoded in the controller
  43.                 'mapped' => false,
  44.                 'label' => false,
  45.                 'attr' => ['autocomplete' => 'new-password'],
  46.                 'constraints' => [
  47.                     new NotBlank([
  48.                         'message' => 'Veuillez saisir un mot de passe',
  49.                     ]),
  50.                     new Length([
  51.                         'min' => 6,
  52.                         'minMessage' => 'Votre mot de passe doit comporter {{ limit }} caractères',
  53.                         // max length allowed by Symfony for security reasons
  54.                         'max' => 4096,
  55.                     ]),
  56.                 ],
  57.             ])
  58.         ;
  59.     }
  60.     public function configureOptions(OptionsResolver $resolver): void
  61.     {
  62.         $resolver->setDefaults([
  63.             'data_class' => User::class,
  64.         ]);
  65.     }
  66. }