<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
class RegistrationFormType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array<mixed> $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, [
'label' => 'form.email',
'constraints' => [
new Assert\NotBlank([
'message' => 'Molimo Vas unesite vas Email',
]),
new Assert\Email([
'message' => 'Molimo Vas unesite ispravnu E-mail adresu'
])
]
])
->add('plainPassword', RepeatedType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'type' => PasswordType::class,
'options' => [
'attr' => [
'autocomplete' => 'new-password',
],
],
'required' => true,
'first_options' => ['label' => 'form.password'],
'second_options' => ['label' => 'form.password_confirmation'],
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new Assert\NotBlank([
'message' => 'Molimo Vas unesite šifru',
]),
new Assert\Length([
'min' => 6,
'minMessage' => 'Vaša šifra mora da sadrži minimum {{ limit }} karaktera',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
'invalid_message' => 'Neispravne lozinke',
])
->add('firstname', TextType::class, [
'constraints' => [
new Assert\NotBlank([
'message' => 'Molimo Vas unesite vase Ime',
]),
new Assert\Length([
'min' => 2,
'minMessage' => 'Ime mora da sadrži minimum {{ limit }} karaktera',
'max' => 30,
'maxMessage' => 'Ime može da sadrži maksimalno {{ limit }} karaktera'
]),
]
])
->add('lastname', TextType::class, [
'constraints' => [
new Assert\NotBlank([
'message' => 'Molimo Vas unestie vase Prezime',
]),
new Assert\Length([
'min' => 2,
'minMessage' => 'Prezime mora da sadrži minimum {{ limit }} karaktera',
'max' => 30,
'maxMessage' => 'Prezime može da sadrži maksimalno {{ limit }} karaktera'
]),
]
])
->add('phone_number', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'min' => 6,
'minMessage' => 'Broj telefona mora da sadrži minimum {{ limit }} karaktera',
'max' => 30,
'maxMessage' => 'Broj telefona da sadrži maksimalno {{ limit }} karaktera'
]),
]
])
->add('hasAcceptedTerms', CheckboxType::class, [
'constraints' => [
new Assert\IsTrue([
'message' => 'Molimo Vas da prihvatite uslove korišćenja.',
]),
],
])
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
'csrf_token_id' => 'registration',
]);
}
/**
* @return string
*/
public function getBlockPrefix(): string
{
return 'app_user_registration';
}
}