src/Form/RegistrationFormType.php line 16

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