src/Form/RegularSignupType.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Api\BrcBackend\DTO\Signup\RegularSignup;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. final class RegularSignupType extends AbstractType
  11. {
  12.     /**
  13.      * @inheritDoc
  14.      */
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('name'TextType::class, [
  19.                 'label' => null,
  20.                 'attr' => [
  21.                     'placeholder' => 'signup.form.name',
  22.                 ],
  23.                 'constraints' => [
  24.                     new Assert\NotBlank(['message' => 'signup.name.not_blank']),
  25.                     new Assert\Length([
  26.                         'max' => 100,
  27.                         'min' => 3,
  28.                         'minMessage' => 'signup.name.length',
  29.                         'maxMessage' => 'signup.name.length',
  30.                     ]),
  31.                 ],
  32.             ])
  33.             ->add('city'TextType::class, [
  34.                 'label' => null,
  35.                 'attr' => [
  36.                     'placeholder' => 'signup.form.city',
  37.                 ],
  38.                 'constraints' => [
  39.                     new Assert\NotBlank(['message' => 'signup.city.not_blank']),
  40.                     new Assert\Length([
  41.                         'max' => 100,
  42.                         'min' => 3,
  43.                         'minMessage' => 'signup.city.length',
  44.                         'maxMessage' => 'signup.city.length',
  45.                     ]),
  46.                 ],
  47.             ])
  48.             ->add('phone'TextType::class, [
  49.                 'label' => null,
  50.                 'attr' => [
  51.                     'placeholder' => 'signup.form.phone',
  52.                 ],
  53.                 'constraints' => [
  54.                     new Assert\NotBlank(['message' => 'signup.phone.not_blank']),
  55.                     new Assert\Regex([
  56.                         'pattern' => '/^\d+$/',
  57.                         'message' => 'signup.phone.only_digits',
  58.                     ]),
  59.                     new Assert\Length([
  60.                         'min' => 9,
  61.                         'max' => 20,
  62.                         'minMessage' => 'signup.phone.length',
  63.                         'maxMessage' => 'signup.phone.length',
  64.                     ]),
  65.                 ],
  66.             ])
  67.             ->add('submit'SubmitType::class, [
  68.                 'label' => 'signup.form.submit',
  69.                 'attr' => [
  70.                     'class' => 'btn-two',
  71.                 ],
  72.             ])
  73.         ;
  74.     }
  75.     /**
  76.      * @inheritDoc
  77.      */
  78.     public function configureOptions(OptionsResolver $resolver): void
  79.     {
  80.         $resolver->setDefaults([
  81.             'data_class' => RegularSignup::class,
  82.             'attr' => [
  83.                 'autocomplete' => 'off',
  84.             ]
  85.         ]);
  86.     }
  87. }