<?php
namespace App\Form;
use App\Api\BrcBackend\DTO\Signup\RegularSignup;
use Symfony\Component\Form\AbstractType;
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 as Assert;
final class RegularSignupType extends AbstractType
{
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'label' => null,
'attr' => [
'placeholder' => 'signup.form.name',
],
'constraints' => [
new Assert\NotBlank(['message' => 'signup.name.not_blank']),
new Assert\Length([
'max' => 100,
'min' => 3,
'minMessage' => 'signup.name.length',
'maxMessage' => 'signup.name.length',
]),
],
])
->add('city', TextType::class, [
'label' => null,
'attr' => [
'placeholder' => 'signup.form.city',
],
'constraints' => [
new Assert\NotBlank(['message' => 'signup.city.not_blank']),
new Assert\Length([
'max' => 100,
'min' => 3,
'minMessage' => 'signup.city.length',
'maxMessage' => 'signup.city.length',
]),
],
])
->add('phone', TextType::class, [
'label' => null,
'attr' => [
'placeholder' => 'signup.form.phone',
],
'constraints' => [
new Assert\NotBlank(['message' => 'signup.phone.not_blank']),
new Assert\Regex([
'pattern' => '/^\d+$/',
'message' => 'signup.phone.only_digits',
]),
new Assert\Length([
'min' => 9,
'max' => 20,
'minMessage' => 'signup.phone.length',
'maxMessage' => 'signup.phone.length',
]),
],
])
->add('submit', SubmitType::class, [
'label' => 'signup.form.submit',
'attr' => [
'class' => 'btn-two',
],
])
;
}
/**
* @inheritDoc
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => RegularSignup::class,
'attr' => [
'autocomplete' => 'off',
]
]);
}
}