src/Form/RegistrationFormType.php line 22

  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\BirthdayType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\FileType;
  8. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  9. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  17. use Symfony\Component\Form\Extension\Core\Type\DateType;
  18. use Symfony\Component\Validator\Constraints\File;
  19. class RegistrationFormType extends AbstractType
  20. {
  21.     public function buildForm(FormBuilderInterface $builder, array $options): void
  22.     {
  23.         $builder
  24.             ->add('nom'TextType::class, ['label' => false,])
  25.             ->add('prenom'TextType::class, ['label' => false])
  26.             ->add('sexe'ChoiceType::class, [
  27.                 'label' => 'Sexe : ',
  28.                 'attr' => ['class' => 'question'],
  29.                 'choices' => [
  30.                     'Homme' => 'homme',
  31.                     'Femme' => 'femme',
  32.                 ],
  33.                 'choice_attr' => [
  34.                     'Homme' => ['class' => 'custom-space'],
  35.                     'Femme' => ['class' => 'custom-space'],
  36.                 ],
  37.                 'expanded' => true,
  38.             ])
  39.             ->add('email'EmailType ::class, [
  40.                 'label' => false,
  41.             ])
  42.             ->add('photo'FileType::class, [
  43.                 'label' => false,
  44.                 // unmapped means that this field is not associated to any entity property
  45.                 'mapped' => false,
  46.                 // make it optional so you don't have to re-upload the PDF file
  47.                 // every time you edit the Product details
  48.                 'required' => false,
  49.                 // unmapped fields can't define their validation using annotations
  50.                 // in the associated entity, so you can use the PHP constraint classes
  51.                 'constraints' => [
  52.                     new File([
  53.                         'maxSize' => '1024k',
  54.                         'extensions' => [
  55.                             'jpg',
  56.                             'png'
  57.                         ],
  58.                         'mimeTypesMessage' => 'Please upload a valid document',
  59.                     ])
  60.                 ],
  61.             ])
  62.             ->add('date_naissance'DateType::class, [
  63.                 'label' => false,
  64.                 'invalid_message' => 'non valide',
  65.                 'required' => true,
  66.                 'widget' => 'single_text',
  67.                 // this is actually the default format for single_text
  68.                 'format' => 'yyyy-MM-dd',
  69.             ])
  70.             ->add('password'RepeatedType::class, [
  71.                 // instead of being set onto the object directly,
  72.                 // this is read and encoded in the controller
  73.                 'mapped' => false,
  74.                 'type' => PasswordType::class,
  75.                 'attr' => ['autocomplete' => 'new-password'],
  76.                 'first_options' => ['label' => false],
  77.                 'second_options' => ['label' => false],
  78.                 'invalid_message' => 'Les mots de passe ne sont pas identiques',
  79.                 'constraints' => [
  80.                     new Length(['min' => 4'minMessage' => 'le mot de passe doit comporter au moins {{ limit }} caractères''max' => 20'maxMessage' => 'le mot de passe ne peut pas contenir plus de {{ limit }} caractères'])
  81.                 ],
  82.             ]);
  83.     }
  84.     public function configureOptions(OptionsResolver $resolver): void
  85.     {
  86.         $resolver->setDefaults([
  87.             'data_class' => User::class,
  88.             'csrf_protection' => true,
  89.             // the name of the hidden HTML field that stores the token
  90.             'csrf_field_name' => '_token',
  91.             // an arbitrary string used to generate the value of the token
  92.             // using a different string for each form improves its security
  93.             'csrf_token_id'   => 'task_item',
  94.         ]);
  95.     }
  96. }