src/Form/InscriptionForm.php line 23

  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  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\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use  Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  11. use Symfony\Component\Validator\Constraints\Email;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. use Symfony\Component\Validator\Constraints\Type;
  14. use Symfony\Config\Twig\NumberFormatConfig;
  15. /**
  16.  * Reset password email form
  17.  *
  18.  * @package App\Form\
  19.  */
  20. class InscriptionForm extends AbstractType
  21. {
  22.     private UrlGeneratorInterface $urlGenerator;
  23.     public function __construct(UrlGeneratorInterface $urlGenerator)
  24.     {
  25.         $this->urlGenerator $urlGenerator;
  26.     }
  27.     /**
  28.      * @inheritDoc
  29.      *
  30.      * @param FormBuilderInterface $builder
  31.      * @param array $options
  32.      *
  33.      * @throws \Symfony\Component\Routing\Exception\InvalidParameterException
  34.      * @throws \Symfony\Component\Routing\Exception\MissingMandatoryParametersException
  35.      * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
  36.      */
  37.     public function buildForm(FormBuilderInterface $builder, array $options)
  38.     {
  39.         $builder->setAction($this->urlGenerator->generate('inscription'))
  40.             ->add('type'ChoiceType::class, [
  41.                 'choices' => [
  42.                     'Distributeur' => 'ROLE_DISTRIBUTEUR',
  43.                     'Installateur' => 'ROLE_INSTALLATEUR' ,
  44.                     'Prescripteur' => 'ROLE_PRESCRIPTEUR' ,
  45.                     'Utilisateur particulier' => 'ROLE_USER_PARTICULIER',
  46.                     'Utilisateur professionnel' => 'ROLE_USER_PROFESIONNEL'
  47.                 ],
  48.                 'expanded' => false,
  49.                 'multiple' => false,
  50.                 'label' => 'Vous êtes',
  51.                 'constraints' => [
  52.                     new NotBlank([
  53.                         'message' => 'Veuillez choisir un type de compte'
  54.                     ])
  55.                 ],
  56.                 'attr' => [
  57.                     'class' => 'form-control mt-2 mb-2'
  58.                 ]
  59.             ])
  60.             ->add('nom'TextType::class, [
  61.                 'label' => 'Nom',
  62.                 'constraints' => [
  63.                     new NotBlank([
  64.                         'message' => 'Veuillez saisir votre nom'
  65.                     ])
  66.                 ],
  67.                 'attr' => [
  68.                     'class' => 'form-control mt-2 mb-2'
  69.                 ]
  70.             ])
  71.             ->add('prenom'TextType::class, [
  72.                 'label' => 'Prénom',
  73.                 'constraints' => [
  74.                     new NotBlank([
  75.                         'message' => 'Veuillez saisir votre prénom'
  76.                     ])
  77.                 ],
  78.                 'attr' => [
  79.                     'class' => 'form-control mt-2 mb-2'
  80.                 ]
  81.             ])
  82.             ->add('tel'TextType::class, [
  83.                 'label' => 'Téléphone',
  84.                 'help' => 'Format : 0123456789',
  85.                 'constraints' => [
  86.                     new NotBlank([
  87.                         'message' => 'Veuillez saisir votre numéro de téléphone'
  88.                     ]),
  89.                     new Type([
  90.                         'type' => 'numeric',
  91.                         'message' => 'Veuillez saisir un numéro de téléphone valide'
  92.                     ])
  93.                 ],
  94.                 'attr' => [
  95.                     'class' => 'form-control mt-2 mb-2'
  96.                 ]
  97.             ])
  98.             ->add('email'EmailType::class, [
  99.                 'label' => 'Email',
  100.                 'constraints' => [
  101.                     new NotBlank([
  102.                         'message' => 'Veuillez saisir votre email'
  103.                     ]),
  104.                     new Email([
  105.                         'message' => 'Veuillez saisir un email valide'
  106.                     ])
  107.                 ],
  108.                 'attr' => [
  109.                     'class' => 'form-control mt-2 mb-2'
  110.                 ]
  111.             ])
  112.             ->add('societe'TextType::class, [
  113.                 'label' => 'Société',
  114.                 'required' => false,
  115.                 'constraints' => [
  116.                     new NotBlank([
  117.                         'message' => 'Veuillez saisir le nom de votre société'
  118.                     ])
  119.                 ],
  120.                 'attr' => [
  121.                     'class' => 'form-control mt-2 mb-2'
  122.                 ]
  123.             ])
  124.             ->add('fonction'TextType::class, [
  125.                 'label' => 'Fonction',
  126.                 'required' => false,
  127.                 'constraints' => [
  128.                     new NotBlank([
  129.                         'message' => 'Veuillez saisir votre fonction'
  130.                     ])
  131.                 ],
  132.                 'attr' => [
  133.                     'class' => 'form-control mt-2 mb-2'
  134.                 ]
  135.             ])
  136.             ->add('adresse'TextType::class, [
  137.                 'label' => 'Adresse',
  138.                 'constraints' => [
  139.                     new NotBlank([
  140.                         'message' => 'Veuillez saisir votre adresse'
  141.                     ])
  142.                 ],
  143.                 'attr' => [
  144.                     'class' => 'form-control mt-2 mb-2'
  145.                 ]
  146.             ])
  147.             ->add('codePostal'TextType::class, [
  148.                 'label' => 'Code postal',
  149.                 'constraints' => [
  150.                     new NotBlank([
  151.                         'message' => 'Veuillez saisir votre code postal'
  152.                     ]),
  153.                     new Type([
  154.                         'type' => 'numeric',
  155.                         'message' => 'Veuillez saisir un code postal valide'
  156.                     ])
  157.                 ],
  158.                 'attr' => [
  159.                     'class' => 'form-control mt-2 mb-2'
  160.                 ]
  161.             ])
  162.             ->add('ville'TextType::class, [
  163.                 'label' => 'Ville',
  164.                 'constraints' => [
  165.                     new NotBlank([
  166.                         'message' => 'Veuillez saisir votre ville'
  167.                     ])
  168.                 ],
  169.                 'attr' => [
  170.                     'class' => 'form-control mt-2 mb-2'
  171.                 ]
  172.             ])
  173.             ->add('password'PasswordType::class, [
  174.                 'label' => 'Mot de passe',
  175.                 'constraints' => [
  176.                     new NotBlank([
  177.                         'message' => 'Veuillez saisir votre mot de passe'
  178.                     ])
  179.                 ],
  180.                 'attr' => [
  181.                     'class' => 'form-control mt-2 mb-2'
  182.                 ]
  183.             ])
  184.             ->add('newsletter'CheckboxType::class, [
  185.                 'label' => 'Je souhaite recevoir la newsletter',
  186.                 'required' => false,
  187.                 'attr' => [
  188.                     'class' => 'form-check-input'
  189.                 ]
  190.             ]);
  191.     }
  192. }