src/Form/RegistrationFormType.php line 16

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\Extension\Core\Type\TextType;
  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. class RegistrationFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('email'TextType::class, [
  19.                 'label' => false,
  20.                 'attr' => ['placeholder' => 'Entrez votre adresse email'],
  21.             ])
  22.             // ->add('telephone', TextType::class, [
  23.             //     'label' => false
  24.             // ])
  25.             ->add('userName'TextType::class, [
  26.                 'label' => false,
  27.                 'attr' => ['placeholder' => 'Entrez un nom d\'utilisateur'],
  28.             ])
  29.             ->add('agreeTerms'CheckboxType::class, [
  30.                 'mapped' => false,
  31.                 'label' => false,
  32.                 'constraints' => [
  33.                     new IsTrue([
  34.                         'message' => 'Vous devez acceptez nos conditions d\'utilisation.',
  35.                     ]),
  36.                 ],
  37.             ])
  38.             ->add('plainPassword'PasswordType::class, [
  39.                 // instead of being set onto the object directly,
  40.                 // this is read and encoded in the controller
  41.                 'mapped' => false,
  42.                 'label' => false,
  43.                 'attr' => ['autocomplete' => 'new-password''placeholder' => 'Entrez votre mot de passe',],
  44.                 'constraints' => [
  45.                     new NotBlank([
  46.                         'message' => 'Veuillez entrez un mot de passe',
  47.                     ]),
  48.                     new Length([
  49.                         'min' => 6,
  50.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  51.                         // max length allowed by Symfony for security reasons
  52.                         'max' => 4096,
  53.                     ]),
  54.                 ],
  55.             ]);
  56.     }
  57.     public function configureOptions(OptionsResolver $resolver): void
  58.     {
  59.         $resolver->setDefaults([
  60.             'data_class' => User::class,
  61.         ]);
  62.     }
  63. }