<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
class B2cSubscriptionType extends AbstractType
{
public function __construct(private readonly TranslatorInterface $translator)
{
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('firstName', TextType::class, [
'mapped' => false,
'label' => $this->translator->trans('Pages.SignUp.Fields.FirstName', [], 'messages_front'),
'constraints' => [
new NotBlank(),
],
'attr' => [
'placeholder' =>
$this->translator->trans('Pages.SignUp.Fields.FirstName', [], 'messages_front')
]
])
->add('lastName', TextType::class, [
'label' => $this->translator->trans('Pages.SignUp.Fields.LastName', [], 'messages_front'),
'mapped' => false,
'constraints' => [
new NotBlank(),
],
'attr' => [
'placeholder' =>
$this->translator->trans('Pages.SignUp.Fields.LastName', [], 'messages_front')
]
])
->add('email', EmailType::class, [
'attr' => [
'placeholder' => $this->translator->trans('Pages.SignUp.Fields.Email', [], 'messages_front'),
],
'label' => $this->translator->trans('Pages.SignUp.Fields.Email', [], 'messages_front'),
'constraints' => [
new NotBlank(),
new Email([
'message' => 'Please enter a valid email address',
'mode' => 'strict', // optional: can be 'loose' or 'html5'
]),
]
])
->add('password', RepeatedType::class, [
'type' => PasswordType::class,
'required' => true,
// 'invalid_message' => 'The password fields must match.',
'options' => ['attr' => ['class' => 'password-field']],
'first_options' => [
'data' => $options['data']->getPassword() ?? null,
'label' => $this->translator->trans('Pages.SignUp.Fields.Password', [], 'messages_front'),
'attr' =>
[
'autocomplete' => 'new-password',
'placeholder' => $this->translator->trans('Pages.SignUp.Fields.Password', [], 'messages_front')
],
],
'second_options' => [
'data' => $options['data']->getPassword() ?? null,
'label' => $this->translator->trans('Pages.SignUp.Fields.VerifPassword', [], 'messages_front'),
'attr' => [
'autocomplete' => 'new-password',
'placeholder' => $this->translator->trans('Pages.SignUp.Fields.VerifPassword', [], 'messages_front')
],
],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
])
],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
'novalidate' => 'novalidate',
]);
}
public function getBlockPrefix(): string
{
return '';
}
}