<?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\NumberType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, [
'required' => true,
'label' => 'Emailová adresa *',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte emailovou adresu',
]),
],
])
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => [
'label' => 'Heslo *',
'row_attr' => [
'class' => 'form-floating mb-3',
],
],
'second_options' => [
'label' => 'Zopakujte heslo *',
'row_attr' => [
'class' => 'form-floating mb-3',
],
],
'mapped' => false,
'required' => true,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte heslo',
]),
new Length([
'min' => 6,
'minMessage' => 'Heslo musí obsahovat minimálně {{ limit }} znaků',
// max length allowed by Symfony for security reasons
'max' => 100,
'maxMessage' => 'Heslo může obsahovat maxmimálně {{ limit }} znaků',
]),
],
])
->add('firstname', TextType::class, [
'required' => true,
'label' => 'Jméno *',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte jméno',
]),
],
])
->add('lastname', TextType::class, [
'required' => true,
'label' => 'Příjmení *',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte příjmení',
]),
],
])
->add('phone', NumberType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte telefonní číslo',
]),
],
'label' => 'Telefonní číslo *',
])
->add('country', TextType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte zemi',
]),
],
'label' => 'Země *',
])
->add('city', TextType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte město',
]),
],
'label' => 'Město *',
])
->add('zipcode', TextType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte PSČ',
]),
],
'label' => 'PSČ *',
])
->add('street', TextType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte ulici',
]),
],
'label' => 'Ulice *',
])
->add('street2', TextType::class, [
'label' => 'Apt. nr., floor',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'required' => false,
])
->add('terms', CheckboxType::class, [
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'Pro registraci musíte souhlasit s podmínkami.',
]),
],
'required' => true,
'label' => 'Souhlasím s <a href="{{ path(\'app_terms\') }}">podmínkami</a> používání této služby.',
'label_html' => true
])
->add('save', SubmitType::class, [
'label' => 'Registrovat se'
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
// enable/disable CSRF protection for this form
'csrf_protection' => true,
// the name of the hidden HTML field that stores the token
'csrf_field_name' => '_token',
// an arbitrary string used to generate the value of the token
// using a different string for each form improves its security
'csrf_token_id' => 'task_item',
]);
}
}