src/Form/RegistrationFormType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use App\Validator\UniqueUserEmail;
  5. use Symfony\Component\Form\AbstractType;
  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\RepeatedType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\Email;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. use Symfony\Component\Validator\Constraints\Sequentially;
  15. class RegistrationFormType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $builder
  20.             ->add('email'EmailType::class, [
  21.                 'label'      => '<i class="far fa-envelope"></i> Adresse Email',
  22.                 'label_html' => true,
  23.                 'attr'       => [
  24.                     'placeholder' => 'e.g. jeanmichel@gmail.com',
  25.                     'class'       => 'form-control',
  26.                 ],
  27.                 'constraints' => [
  28.                     new Sequentially([
  29.                         new Email(),
  30.                         new UniqueUserEmail(),
  31.                     ]),
  32.                 ],
  33.                 'row_attr' => [
  34.                     'class' => 'form-row',
  35.                 ],
  36.             ])
  37.             ->add('password'RepeatedType::class, [
  38.                 // instead of being set onto the object directly,
  39.                 // this is read and encoded in the controller
  40.                 'type'            => PasswordType::class,
  41.                 'label'           => '<i class="fas fa-key fa-fw"></i> Mot de passe',
  42.                 'label_html'      => true,
  43.                 'invalid_message' => 'Les mots de passes ne correspondent pas.',
  44.                 'first_options'   => [
  45.                     'label'      => '<i class="fas fa-key fa-fw"></i> Mot de passe',
  46.                     'label_html' => true,
  47.                     'attr'       => [
  48.                         'autocomplete' => 'new-password',
  49.                         'placeholder'  => '*******',
  50.                         'class'        => 'form-control',
  51.                     ],
  52.                     'row_attr' => [
  53.                         'class' => 'form-row',
  54.                     ],
  55.                 ],
  56.                 'second_options' => [
  57.                     'label'      => '<i class="fas fa-key fa-fw"></i> Confirmer le mot de passe',
  58.                     'label_html' => true,
  59.                     'attr'       => [
  60.                         'autocomplete' => 'new-password',
  61.                         'placeholder'  => '*******',
  62.                         'class'        => 'form-control',
  63.                     ],
  64.                     'row_attr' => [
  65.                         'class' => 'form-row',
  66.                     ],
  67.                 ],
  68.                 'constraints' => [
  69.                     new NotBlank([
  70.                         'message' => 'Veuillez entrer un mot de passe',
  71.                     ]),
  72.                     new Length([
  73.                         'min'        => 6,
  74.                         'minMessage' => 'Votre mot de passe doit être au moins de {{ limit }} charactères',
  75.                         // max length allowed by Symfony for security reasons
  76.                         'max' => 4096,
  77.                     ]),
  78.                 ],
  79.             ])
  80.         ;
  81.     }
  82.     public function configureOptions(OptionsResolver $resolver): void
  83.     {
  84.         $resolver->setDefaults([
  85.             'step'       => null,
  86.             'data_class' => User::class,
  87.         ]);
  88.     }
  89. }