src/Form/B2cSubscriptionType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  6. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\Email;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. class B2cSubscriptionType extends AbstractType
  15. {
  16.     public function __construct(private readonly TranslatorInterface $translator)
  17.     {
  18.     }
  19.     public function buildForm(FormBuilderInterface $builder, array $options): void
  20.     {
  21.          $builder
  22.              ->add('firstName'TextType::class, [
  23.                  'mapped' => false,
  24.                  'label' => $this->translator->trans('Pages.SignUp.Fields.FirstName', [], 'messages_front'),
  25.                  'constraints' => [
  26.                      new NotBlank(),
  27.                  ],
  28.                  'attr' => [
  29.                      'placeholder' =>
  30.                          $this->translator->trans('Pages.SignUp.Fields.FirstName', [], 'messages_front')
  31.                  ]
  32.              ])
  33.              ->add('lastName'TextType::class, [
  34.                  'label' => $this->translator->trans('Pages.SignUp.Fields.LastName', [], 'messages_front'),
  35.                  'mapped' => false,
  36.                  'constraints' => [
  37.                      new NotBlank(),
  38.                  ],
  39.                  'attr' => [
  40.                      'placeholder' =>
  41.                          $this->translator->trans('Pages.SignUp.Fields.LastName', [], 'messages_front')
  42.                  ]
  43.              ])
  44.             ->add('email'EmailType::class, [
  45.                     'attr' => [
  46.                         'placeholder' => $this->translator->trans('Pages.SignUp.Fields.Email', [], 'messages_front'),
  47.                     ],
  48.                     'label' => $this->translator->trans('Pages.SignUp.Fields.Email', [], 'messages_front'),
  49.                     'constraints' => [
  50.                         new NotBlank(),
  51.                         new Email([
  52.                             'message' => 'Please enter a valid email address',
  53.                             'mode' => 'strict'// optional: can be 'loose' or 'html5'
  54.                         ]),
  55.                     ]
  56.                 ])
  57.             ->add('password'RepeatedType::class, [
  58.                 'type' => PasswordType::class,
  59.                 'required' => true,
  60. //                'invalid_message' => 'The password fields must match.',
  61.                 'options' => ['attr' => ['class' => 'password-field']],
  62.                 'first_options' => [
  63.                     'data' => $options['data']->getPassword() ?? null,
  64.                     'label' => $this->translator->trans('Pages.SignUp.Fields.Password', [], 'messages_front'),
  65.                     'attr' =>
  66.                         [
  67.                             'autocomplete' => 'new-password',
  68.                             'placeholder' => $this->translator->trans('Pages.SignUp.Fields.Password', [], 'messages_front')
  69.                         ],
  70.                 ],
  71.                 'second_options' => [
  72.                     'data' => $options['data']->getPassword() ?? null,
  73.                     'label' => $this->translator->trans('Pages.SignUp.Fields.VerifPassword', [], 'messages_front'),
  74.                     'attr' => [
  75.                         'autocomplete' => 'new-password',
  76.                         'placeholder' => $this->translator->trans('Pages.SignUp.Fields.VerifPassword', [], 'messages_front')
  77.                     ],
  78.                 ],
  79.                 'constraints' => [
  80.                     new NotBlank([
  81.                         'message' => 'Please enter a password',
  82.                     ])
  83.                 ],
  84.             ]);
  85.     }
  86.     public function configureOptions(OptionsResolver $resolver): void
  87.     {
  88.         $resolver->setDefaults([
  89.             'data_class' => User::class,
  90.             'novalidate' => 'novalidate',
  91.         ]);
  92.     }
  93.     public function getBlockPrefix(): string
  94.     {
  95.         return '';
  96.     }
  97. }