src/Form/RegistrationFormType.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Applicants;
  4. use App\Form\ReCaptchaType\ReCaptchaType;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  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. use Symfony\Contracts\Translation\TranslatorInterface;
  16. class RegistrationFormType extends AbstractType
  17. {
  18.     public const PASSWORD 'plainPassword';
  19.     public const CONFIRMED_PASSWORD 'confirmedPassword';
  20.     public function __construct(private TranslatorInterface $translator)
  21.     {
  22.     }
  23.     public function buildForm(FormBuilderInterface $builder, array $options): void
  24.     {
  25.         $builder
  26.             ->add('fName'null, [
  27.                 "required" => true,
  28.                 "attr"=> [
  29.                     "placeholder" => $this->translator->trans("required")
  30.                 ]
  31.             ])
  32.             ->add('lName'null, [
  33.                 "required" => true,
  34.                 "attr"=> [
  35.                     "placeholder" => $this->translator->trans("required")
  36.                 ]
  37.             ])
  38.             ->add('email'EmailType::class, [
  39.                 'label' => 'Email',
  40.                 "required" => true,
  41.                 "attr"=> [
  42.                     "placeholder" => $this->translator->trans("required")
  43.                 ]
  44.             ])
  45.             ->add('sex'ChoiceType::class, [
  46.                 "choices" => [
  47.                     "Homme" => true,
  48.                     "Femme" => false,
  49.                 ],
  50.                 "attr"=> [
  51.                     "placeholder" => $this->translator->trans("required")
  52.                 ]
  53.             ])
  54.             ->add('agreeTerms'CheckboxType::class, [
  55.                 'mapped' => false,
  56.                 "required" => true,
  57.                 'constraints' => [
  58.                     new IsTrue([
  59.                         'message' => 'You should agree to our terms.',
  60.                     ]),
  61.                 ],
  62.                 "attr"=> [
  63.                     "placeholder" => $this->translator->trans("required"),
  64.                     "class" => "os-checkbox"
  65.                 ]
  66.             ])
  67.             ->add(self::PASSWORDPasswordType::class, [
  68.                 'mapped' => false,
  69.                 'attr' => ['autocomplete' => 'new-password'"placeholder" => $this->translator->trans("required")],
  70.                 'constraints' => [
  71.                     new NotBlank([
  72.                         'message' => 'Please enter a password',
  73.                     ]),
  74.                     new Length([
  75.                         'min' => 6,
  76.                         'minMessage' => $this->translator->trans("password.minLength"),
  77.                         'max' => 4096,
  78.                     ]),
  79.                 ],
  80.             ])
  81.             ->add(self::CONFIRMED_PASSWORDPasswordType::class, [
  82.                 'mapped' => false,
  83.                 'attr' => ['autocomplete' => 'new-password'"placeholder" => $this->translator->trans("required")],
  84.                 'constraints' => [
  85.                     new NotBlank([
  86.                         'message' => 'Please enter a password',
  87.                     ]),
  88.                     new Length([
  89.                         'min' => 6,
  90.                         'minMessage' => $this->translator->trans("password.minLength"),
  91.                         'max' => 4096,
  92.                     ]),
  93.                 ],
  94.             ])->add('recaptcha'ReCaptchaType::class, [
  95.                 "required" => true,
  96.             ])
  97.         ;
  98.     }
  99.     public function configureOptions(OptionsResolver $resolver): void
  100.     {
  101.         $resolver->setDefaults([
  102.             'data_class' => Applicants::class,
  103.             "attr"=>[
  104.                 "id"=>"registration"
  105.             ]
  106.         ]);
  107.     }
  108. }