src/Form/Front/User/Registration/RegistrationFormType.php line 90

Open in your IDE?
  1. <?php
  2. /*
  3.  * Unauthorized copying of this file, via any medium is strictly prohibited
  4.  * Proprietary and confidential.
  5.  *
  6.  * @author Bilel AZRI          <azri.bilel@gmail.com>
  7.  * @author Assma BEN SASSI     <bensassiasma.bws@gmail.com>
  8.  *
  9.  * Bicking man (c) 2019-present.
  10.  */
  11. declare(strict_types=1);
  12. namespace App\Form\Front\User\Registration;
  13. use App\Entity\User\Participant;
  14. use App\Enum\UserGenderEnum;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\DateType;
  19. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  20. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  21. use Symfony\Component\Form\Extension\Core\Type\TextType;
  22. use Symfony\Component\Form\FormBuilderInterface;
  23. use Symfony\Component\OptionsResolver\OptionsResolver;
  24. use Symfony\Component\Validator\Constraints\IsTrue;
  25. use Symfony\Component\Validator\Constraints\Length;
  26. use Symfony\Component\Validator\Constraints\NotBlank;
  27. class RegistrationFormType extends AbstractType
  28. {
  29.     public function buildForm(FormBuilderInterface $builder, array $options): void
  30.     {
  31.         $builder
  32.             ->add('name'TextType::class, [
  33.                 'required' => true,
  34.             ])
  35.             ->add('lastname'TextType::class, [
  36.                 'required' => true,
  37.             ])
  38.             ->add('email'EmailType::class, [
  39.                 'required' => true,
  40.             ])
  41.             ->add('agreeTerms'CheckboxType::class, [
  42.                 'mapped' => false,
  43.                 'attr' => [
  44.                   'class' => '',
  45.                 ],
  46.                 'constraints' => [
  47.                     new IsTrue([
  48.                         'message' => 'You should agree to our terms.',
  49.                     ]),
  50.                 ],
  51.                 //'data' => true,
  52.             ])
  53.             ->add('plainPassword'PasswordType::class, [
  54.                 // instead of being set onto the object directly,
  55.                 // this is read and encoded in the controller
  56.                 'mapped' => false,
  57.                 'constraints' => [
  58.                     new NotBlank([
  59.                         'message' => 'Please enter a password',
  60.                     ]),
  61.                     new Length([
  62.                         'min' => 6,
  63.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  64.                         // max length allowed by Symfony for security reasons
  65.                         'max' => 4096,
  66.                     ]),
  67.                 ],
  68.             ])
  69.             ->add('dateOfBirth'TextType::class, [
  70.                 //'html5' => true,
  71.                 'required' => false,
  72.                 //'widget' => 'single_text',
  73.                 'attr' => [
  74.                     'class' => 'form-control js-datepicker',
  75.                 ],
  76.             ])
  77.             /*->add('dateOfBirth', TextType::class, [
  78.                 'required' => true,
  79.                 'attr' => [
  80.                     'class' => 'form-control js-datepicker',
  81.                 ],
  82.             ])*/
  83.             ->add('gender'ChoiceType::class, [
  84.                 'choices' => UserGenderEnum::getAvailableGender(),
  85.                 'choice_label' => function (?int $choice): string {
  86.                     return UserGenderEnum::getGenderName($choice);
  87.                 },
  88.                 'constraints' => new NotBlank(),
  89.                 'attr' => [
  90.                     'class' => 'form-control',
  91.                 ],
  92.             ])
  93.         ;
  94.     }
  95.     public function configureOptions(OptionsResolver $resolver): void
  96.     {
  97.         $resolver->setDefaults([
  98.             'data_class' => Participant::class,
  99.         ]);
  100.     }
  101. }