src/Form/RegistrationFormType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Users;
  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\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\IsTrue;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         $builder
  19.             ->add('email'EmailType::class, [
  20.                 'attr' => [
  21.                     'class' => 'form-control'
  22.                 ],
  23.                 'label' => 'E-mail'
  24.             ])
  25.             ->add('phone'TextType::class, [
  26.                 'attr' => [
  27.                     'class' => 'form-control'
  28.                 ],
  29.                 'label' => 'Téléphone fixe'
  30.             ])
  31.             ->add('mobilePhone'TextType::class, [
  32.                 'attr' => [
  33.                     'class' => 'form-control'
  34.                 ],
  35.                 'label' => 'Téléphone portable'
  36.             ])
  37.             ->add('lastname'TextType::class, [
  38.                 'attr' => [
  39.                     'class' => 'form-control'
  40.                 ],
  41.                 'label' => 'Nom'
  42.             ])
  43.             ->add('firstname'TextType::class, [
  44.                 'attr' => [
  45.                     'class' => 'form-control'
  46.                 ],
  47.                 'label' => 'Prénom'
  48.             ])
  49.             ->add('address'TextType::class, [
  50.                 'attr' => [
  51.                     'class' => 'form-control'
  52.                 ],
  53.                 'label' => 'Adresse'
  54.             ])
  55.             ->add('zipcode'TextType::class, [
  56.                 'attr' => [
  57.                     'class' => 'form-control'
  58.                 ],
  59.                 'label' => 'Code postal'
  60.             ])
  61.             ->add('city'TextType::class, [
  62.                 'attr' => [
  63.                     'class' => 'form-control'
  64.                 ],
  65.                 'label' => 'Ville'
  66.             ])
  67.             ->add('RGPDConsent'CheckboxType::class, [
  68.                 'mapped' => false,
  69.                 'constraints' => [
  70.                     new IsTrue([
  71.                         'message' => 'You should agree to our terms.',
  72.                     ]),
  73.                 ],
  74.                 'label' => 'En m\'inscrivant à ce site j\'accepte...'
  75.             ])
  76.             ->add('plainPassword'PasswordType::class, [
  77.                 // instead of being set onto the object directly,
  78.                 // this is read and encoded in the controller
  79.                 'mapped' => false,
  80.                 'attr' => [
  81.                     'autocomplete' => 'new-password',
  82.                     'class' => 'form-control'
  83.                 ],
  84.                 'constraints' => [
  85.                     new NotBlank([
  86.                         'message' => 'Please enter a password',
  87.                     ]),
  88.                     new Length([
  89.                         'min' => 6,
  90.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  91.                         // max length allowed by Symfony for security reasons
  92.                         'max' => 4096,
  93.                     ]),
  94.                 ],
  95.                 'label' => 'Mot de passe'
  96.             ])
  97.         ;
  98.     }
  99.     public function configureOptions(OptionsResolver $resolver): void
  100.     {
  101.         $resolver->setDefaults([
  102.             'data_class' => Users::class,
  103.         ]);
  104.     }
  105. }