src/Form/RegistrationFormType.php line 18

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\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\SubmitType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints\IsTrue;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. class RegistrationFormType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $builder
  20.             ->add('email'EmailType::class, [
  21.                 'attr' => [
  22.                     'class' => 'form-control'
  23.                 ]
  24.             ])
  25.             ->add('prenom'TextType::class, [
  26.                 'attr' => [
  27.                     'class' => 'form-control'
  28.                 ]
  29.             ])
  30.             ->add('nom'TextType::class, [
  31.                 'attr' => [
  32.                     'class' => 'form-control'
  33.                 ]
  34.             ])
  35.             ->add('plainPassword'PasswordType::class, [
  36.                 // instead of being set onto the object directly,
  37.                 // this is read and encoded in the controller
  38.                 'mapped' => false,
  39.                 'attr' => [
  40.                     'autocomplete' => 'new-password',
  41.                     'class' => 'form-control'
  42.                 ],
  43.                 'constraints' => [
  44.                     new NotBlank([
  45.                         'message' => 'Please enter a password',
  46.                     ]),
  47.                     new Length([
  48.                         'min' => 6,
  49.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  50.                         // max length allowed by Symfony for security reasons
  51.                         'max' => 4096,
  52.                     ]),
  53.                 ],
  54.             ])
  55.             ->add('Inscription'SubmitType::class, [
  56.                 'attr' => [
  57.                     'class' => 'btn btn-validation',
  58.                 ]
  59.             ])
  60.         ;
  61.     }
  62.     public function configureOptions(OptionsResolver $resolver): void
  63.     {
  64.         $resolver->setDefaults([
  65.             'data_class' => User::class,
  66.         ]);
  67.     }
  68. }