<?php
namespace App\Form;
use App\Entity\Users;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('firstname', TextType::class, [
'label' => 'Prénom',
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre prénom.',
]),
],
])
->add('lastname', TextType::class, [
'label' => 'Nom',
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre nom.',
]),
],
])
->add('email', EmailType::class, [
'label' => 'Email',
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre adresse e-mail.',
]),
new Email([
'message' => 'Veuillez entrer une adresse e-mail valide.',
]),
],
])
->add('numberPhone', TextType::class, [
'label' => 'Numéro de téléphone',
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre numéro de téléphone.',
]),
],
])
->add('plainPassword', RepeatedType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'type' => PasswordType::class,
'invalid_message' => "The password fields must match.",
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 8,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
new RegEx([
'pattern' => '/^(?=.*[A-Z]).+$/',
'message' => 'Your password must contain at least one capital letter.',
])
],
])
->add('tvaNumber', TextType::class, [
'label' => 'N° TVA',
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre numéro de TVA.',
]),
],
])
->add('cgvAccepted', CheckboxType::class, [
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'Vous devez accepter les conditions générales.',
]),
],
'label' => 'J\'accepte les Conditions générales de ventes de Delsart',
])
->add('tvaStatus', ChoiceType::class, [
'choices' => [
'Assujetti' => '1',
'Non assujetti' => '2',
'En cours' => '3',
],
'label' => 'Statut TVA',
'mapped' => false, // Champ non mappé à l'entité Users
'attr' => ['class' => 'form-control'],
'placeholder' => 'Sélectionnez un statut',
'data' => '1',
]);
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Users::class,
]);
}
}