src/Form/RegistrationFormType.php line 17

Open in your IDE?
  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\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.     /**
  17.      * @param FormBuilderInterface $builder
  18.      * @param array<mixed> $options
  19.      */
  20.     public function buildForm(FormBuilderInterface $builder, array $options): void
  21.     {
  22.         $builder
  23.             ->add('email'EmailType::class, [
  24.                 'label' => 'form.email',
  25.                 'constraints' => [
  26.                     new Assert\NotBlank([
  27.                         'message' => 'Molimo Vas unesite vas Email',
  28.                     ]),
  29.                     new Assert\Email([
  30.                         'message' => 'Molimo Vas unesite ispravnu E-mail adresu'
  31.                     ])
  32.                 ]
  33.             ])
  34.             ->add('plainPassword'RepeatedType::class, [
  35.                 // instead of being set onto the object directly,
  36.                 // this is read and encoded in the controller
  37.                 'type' => PasswordType::class,
  38.                 'options' => [
  39.                     'attr' => [
  40.                         'autocomplete' => 'new-password',
  41.                     ],
  42.                 ],
  43.                 'required' => true,
  44.                 'first_options' => ['label' => 'form.password'],
  45.                 'second_options' => ['label' => 'form.password_confirmation'],
  46.                 'mapped' => false,
  47.                 'attr' => ['autocomplete' => 'new-password'],
  48.                 'constraints' => [
  49.                     new Assert\NotBlank([
  50.                         'message' => 'Molimo Vas unesite šifru',
  51.                     ]),
  52.                     new Assert\Length([
  53.                         'min' => 6,
  54.                         'minMessage' => 'Vaša šifra mora da sadrži minimum {{ limit }} karaktera',
  55.                         // max length allowed by Symfony for security reasons
  56.                         'max' => 4096,
  57.                     ]),
  58.                 ],
  59.                 'invalid_message' => 'Neispravne lozinke',
  60.             ])
  61.             ->add('firstname'TextType::class, [
  62.                 'constraints' => [
  63.                     new Assert\NotBlank([
  64.                         'message' => 'Molimo Vas unesite vase Ime',
  65.                     ]),
  66.                     new Assert\Length([
  67.                         'min' => 2,
  68.                         'minMessage' => 'Ime mora da sadrži minimum {{ limit }} karaktera',
  69.                         'max' => 30,
  70.                         'maxMessage' => 'Ime može da sadrži maksimalno {{ limit }} karaktera'
  71.                     ]),
  72.                 ]
  73.             ])
  74.             ->add('lastname'TextType::class, [
  75.                 'constraints' => [
  76.                     new Assert\NotBlank([
  77.                         'message' => 'Molimo Vas unestie vase Prezime',
  78.                     ]),
  79.                     new Assert\Length([
  80.                         'min' => 2,
  81.                         'minMessage' => 'Prezime mora da sadrži minimum {{ limit }} karaktera',
  82.                         'max' => 30,
  83.                         'maxMessage' => 'Prezime može da sadrži maksimalno {{ limit }} karaktera'
  84.                     ]),
  85.                 ]
  86.             ])
  87.             ->add('phone_number'TextType::class, [
  88.                 'required' => false,
  89.                 'constraints' => [
  90.                     new Assert\Length([
  91.                         'min' => 6,
  92.                         'minMessage' => 'Broj telefona mora da sadrži minimum {{ limit }} karaktera',
  93.                         'max' => 30,
  94.                         'maxMessage' => 'Broj telefona da sadrži maksimalno {{ limit }} karaktera'
  95.                     ]),
  96.                 ]
  97.             ])
  98.             ->add('hasAcceptedTerms'CheckboxType::class, [
  99.                 'constraints' => [
  100.                     new Assert\IsTrue([
  101.                         'message' => 'Molimo Vas da prihvatite uslove korišćenja.',
  102.                     ]),
  103.                 ],
  104.             ])
  105.             ->add('captcha'Recaptcha3Type::class, [
  106.                 'action_name' => 'contact',
  107.                 'mapped' => false
  108.             ])
  109.         ;
  110.     }
  111.     /**
  112.      * @param OptionsResolver $resolver
  113.      */
  114.     public function configureOptions(OptionsResolver $resolver): void
  115.     {
  116.         $resolver->setDefaults([
  117.             'data_class' => User::class,
  118.             'csrf_token_id' => 'registration',
  119.         ]);
  120.     }
  121.     /**
  122.      * @return string
  123.      */
  124.     public function getBlockPrefix(): string
  125.     {
  126.         return 'app_user_registration';
  127.     }
  128. }