src/Form/RegistrationFormType.php line 17

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Users;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  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\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\IsTrue;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         $builder
  19.             ->add('email', EmailType::class, [
  20.                 'attr' => [
  21.                     'class' => 'form-control'
  22.                 ],
  23.                 'label' => 'E-mail'
  24.             ])
  25.             ->add('lastname', TextType::class, [
  26.                 'attr' => [
  27.                     'class' => 'form-control'
  28.                 ],
  29.                 'label' => 'Nom'
  30.             ])
  31.             ->add('firstname', TextType::class, [
  32.                 'attr' => [
  33.                     'class' => 'form-control'
  34.                 ],
  35.                 'label' => 'Prénom'
  36.             ])
  37.             ->add('address', TextType::class, [
  38.                 'attr' => [
  39.                     'class' => 'form-control'
  40.                 ],
  41.                 'label' => 'Adresse'
  42.             ])
  43.             ->add('zipcode', TextType::class, [
  44.                 'attr' => [
  45.                     'class' => 'form-control'
  46.                 ],
  47.                 'label' => 'Code postal'
  48.             ])
  49.             ->add('city', TextType::class, [
  50.                 'attr' => [
  51.                     'class' => 'form-control'
  52.                 ],
  53.                 'label' => 'Ville'
  54.             ])
  55.             ->add('RGPDConsent', CheckboxType::class, [
  56.                 'mapped' => false,
  57.                 'constraints' => [
  58.                     new IsTrue([
  59.                         'message' => 'You should agree to our terms.',
  60.                     ]),
  61.                 ],
  62.                 'label' => 'En m\'inscrivant à ce site j\'accepte...'
  63.             ])
  64.             ->add('plainPassword', PasswordType::class, [
  65.                 // instead of being set onto the object directly,
  66.                 // this is read and encoded in the controller
  67.                 'mapped' => false,
  68.                 'attr' => [
  69.                     'autocomplete' => 'new-password',
  70.                     'class' => 'form-control'
  71.                 ],
  72.                 'constraints' => [
  73.                     new NotBlank([
  74.                         'message' => 'Please enter a password',
  75.                     ]),
  76.                     new Length([
  77.                         'min' => 4,
  78.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  79.                         // max length allowed by Symfony for security reasons
  80.                         'max' => 4096,
  81.                     ]),
  82.                 ],
  83.                 'label' => 'Mot de passe'
  84.             ])
  85.         ;
  86.     }
  87.     public function configureOptions(OptionsResolver $resolver): void
  88.     {
  89.         $resolver->setDefaults([
  90.             'data_class' => Users::class,
  91.         ]);
  92.     }
  93. }