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('lastname'null, [
  18.                 'label' => 'Nom',
  19.                 'attr' => ['class' => 'form-control']
  20.             ])
  21.             ->add('firstname'null, [
  22.                 'label' => 'Prénom',
  23.                 'attr' => ['class' => 'form-control']
  24.             ])
  25.             ->add('email'null, [
  26.                 'label' => 'Email',
  27.                 'attr' => ['class' => 'form-control']
  28.             ])
  29.             ->add('phone'null, [
  30.                 'label' => 'Numéro de téléphone',
  31.                 'attr' => ['class' => 'form-control']
  32.             ])
  33.             ->add('plainPassword'PasswordType::class, [
  34.                 'label' => 'Mot de passe',
  35.                 'mapped' => false,
  36.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-control'],
  37.                 'constraints' => [
  38.                     new NotBlank([
  39.                         'message' => 'Please enter a password',
  40.                     ]),
  41.                     new Length([
  42.                         'min' => 6,
  43.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  44.                         // max length allowed by Symfony for security reasons
  45.                         'max' => 4096,
  46.                     ]),
  47.                 ],
  48.             ])
  49.         ;
  50.     }
  51.     public function configureOptions(OptionsResolver $resolver): void
  52.     {
  53.         $resolver->setDefaults([
  54.             'data_class' => User::class,
  55.         ]);
  56.     }
  57. }