src/Form/RegistrationFormType.php line 18

  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\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints\IsTrue;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. class RegistrationFormType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $builder
  20.             ->add('firstName'TextType::class, [
  21.             'row_attr' => [
  22.                 'class' => 'col-md-6'
  23.             ],
  24.             'attr' => array(
  25.                 'placeholder' => 'Votre prénom'
  26.             )
  27.             ])
  28.             ->add('lastName'TextType::class, [
  29.             'row_attr' => [
  30.                 'class' =>'col-md-6'
  31.             ],
  32.             'attr' => array(
  33.                 'placeholder' => 'Votre nom'
  34.             )
  35.             ]) 
  36.             ->add('sexe'ChoiceType::class, [
  37.                 'row_attr' => [
  38.                     'class' =>'col-md-6'
  39.                 ],
  40.                 'attr' => array(
  41.                     'placeholder' => 'Votre sexe'
  42.                 ),
  43.                 'choices' => [
  44.                     'homme' =>'m',
  45.                     'femme' => 'f'
  46.                 ],
  47.                 'data' => 'F',
  48.                 'expanded' => true,
  49.                 'label' => 'Votre sexe',
  50.             ]) 
  51.             ->add('email'EmailType::class, [
  52.                 'row_attr' => [
  53.                     'class' => 'col-md-6'
  54.                 ]
  55.             ]) 
  56.             ->add('agreeTerms'CheckboxType::class, [
  57.                 'label' => 'Veuillez accepter les conditions générales en cochant la case',
  58.                 'mapped' => false,
  59.                 'row_attr' => [
  60.                     'class' => 'col-md-6'
  61.                 ],
  62.                 'constraints' => [
  63.                     new IsTrue([
  64.                         'message' => 'You should agree to our terms.',
  65.                     ]),
  66.                 ],
  67.             ])
  68.             ->add('plainPassword'PasswordType::class, [
  69.                 // instead of being set onto the object directly,
  70.                 // this is read and encoded in the controller
  71.                 'mapped' => false,
  72.                 'attr' => ['autocomplete' => 'new-password'],
  73.                 'row_attr' => [
  74.                     'class' => 'col-md-6'
  75.                 ],
  76.                 'constraints' => [
  77.                     new NotBlank([
  78.                         'message' => 'Please enter a password',
  79.                     ]),
  80.                     new Length([
  81.                         'min' => 6,
  82.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  83.                         // max length allowed by Symfony for security reasons
  84.                         'max' => 4096,
  85.                     ]),
  86.                 ],
  87.             ])
  88.         ;
  89.     }
  90.     public function configureOptions(OptionsResolver $resolver): void
  91.     {
  92.         $resolver->setDefaults([
  93.             'data_class' => User::class,
  94.         ]);
  95.     }
  96. }