src/Form/Security/StepperType.php line 17

  1. <?php
  2. namespace App\Form\Security;
  3. use App\Service\Twig\Strings;
  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\IsTrue;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class StepperType extends AbstractType
  15. {
  16.     public function __construct(
  17.         private readonly Strings $strings
  18.     ){}
  19.     /**
  20.      * @throws \Doctrine\ORM\NonUniqueResultException
  21.      */
  22.     public function buildForm(FormBuilderInterface $builder, array $options)
  23.     {
  24.         $builder
  25.             ->add('email'EmailType::class, [
  26.                 "label" => false,
  27.                 "required" => false,
  28.                 "constraints" => new NotBlank([
  29.                     "message" => $this->strings->getTranslationString("email_cannot_be_empty")
  30.                 ])
  31.             ])
  32.             ->add('phone'TextType::class, [
  33.                 "label" => false,
  34.                 "required" => false,
  35.                 "constraints" => new NotBlank([
  36.                     "message" => $this->strings->getTranslationString("phone_cannot_be_empty")
  37.                 ])
  38.             ])
  39.             ->add('firstName'TextType::class, [
  40.                 "label" => false,
  41.                 "required" => false,
  42.                 "constraints" => new NotBlank([
  43.                     "message" => $this->strings->getTranslationString("name_surname_cannot_be_empty")
  44.                 ])
  45.             ])
  46.             ->add('lastName'TextType::class, [
  47.                 "label" => false,
  48.                 "required" => false,
  49.                 "constraints" => new NotBlank([
  50.                     "message" => $this->strings->getTranslationString("name_surname_cannot_be_empty")
  51.                 ])
  52.             ])
  53.             ->add('companyName'TextType::class, [
  54.                 "label" => false,
  55.                 "required" => false,
  56.                 "constraints" => new NotBlank([
  57.                     "message" => $this->strings->getTranslationString("company_cannot_be_empty")
  58.                 ])
  59.             ])
  60.             ->add('pin'TextType::class, [
  61.                 "label" => false,
  62.                 "required" => false,
  63.                 "constraints" => new NotBlank([
  64.                     "message" => $this->strings->getTranslationString("pin_cannot_be_empty")
  65.                 ])
  66.             ])
  67.             ->add('password'RepeatedType::class, array(
  68.                 'type' => PasswordType::class,
  69.                 "invalid_message" => $this->strings->getTranslationString("passwords_doesnt_match"),
  70.                 'first_options'  => array(
  71.                     'label' => 'Password',
  72.                     "invalid_message" => $this->strings->getTranslationString("passwords_doesnt_match")
  73.                 ),
  74.                 'second_options' => array(
  75.                     'label' => 'Repeat Password',
  76.                     "invalid_message" => $this->strings->getTranslationString("passwords_doesnt_match")
  77.                 ),
  78.                 "constraints" => [
  79.                     new NotBlank([
  80.                         "message" => $this->strings->getTranslationString("password_cannot_be_empty")
  81.                     ])
  82.                 ],
  83.                 "required" => false
  84.             ))
  85.             ->add('agreeTerms'CheckboxType::class, array(
  86.                 'mapped' => false,
  87.                 'constraints' => new IsTrue([
  88.                     "message" => $this->strings->getTranslationString("please_accept_terms_text")
  89.                 ]),
  90.                 'attr' => array('class'=>'custom-control-input'),
  91.                 'required' => false
  92.             ))
  93.         ;
  94.     }
  95.     public function configureOptions(OptionsResolver $resolver)
  96.     {
  97.         $resolver->setDefaults(array(
  98.             'data_class' => NULL,
  99.             'csrf_protection' => true
  100.         ));
  101.     }
  102. }