src/Form/RegisterUserType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  5. use Symfony\Component\Form\AbstractType;
  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\RepeatedType;
  9. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. class RegisterUserType extends AbstractType
  15. {
  16. public function buildForm(FormBuilderInterface $builder, array $options): void
  17. {
  18. $builder
  19. ->add('firstname', TextType::class, [
  20. 'label' => "Votre prenom",
  21. 'constraints' => [
  22. new Length([
  23. 'min' => 3,
  24. 'max' => 20
  25. ])
  26. ],
  27. 'attr' => [
  28. 'placeholder' => "Entrer votre prenom"
  29. ]
  30. ])
  31. ->add('lastname', TextType::class, [
  32. 'label' => "Votre nom",
  33. 'constraints' => [
  34. new Length([
  35. 'min' => 3,
  36. 'max' => 20
  37. ])
  38. ],
  39. 'attr' => [
  40. 'placeholder' => "Entrer votre nom"
  41. ]
  42. ])
  43. ->add('email', EmailType::class, [
  44. 'label' => "Votre adresse mail",
  45. 'attr' => [
  46. 'placeholder' => "Entrer votre email"
  47. ]
  48. ])
  49. ->add('plainPassword', RepeatedType::class, [
  50. 'type' => PasswordType::class,
  51. 'constraints' => [
  52. new Length([
  53. 'min' => 3,
  54. 'max' => 20
  55. ])
  56. ],
  57. 'first_options' => [
  58. 'label' => 'Votre mot de passe',
  59. 'attr' => [
  60. 'placeholder' => 'Entrez votre mot de passe'
  61. ]
  62. ],
  63. 'second_options' => [
  64. 'label' => 'Confirmer votre mot de passe',
  65. 'attr' => ['placeholder' => 'Confirmez votre mot de passe']
  66. ],
  67. 'mapped' => false,
  68. ])
  69. ->add('submit', SubmitType::class, [
  70. 'label' => "Valider",
  71. 'attr' => [
  72. 'class' => "btn btn-success"
  73. ]
  74. ])
  75. ;
  76. }
  77. public function configureOptions(OptionsResolver $resolver): void
  78. {
  79. $resolver->setDefaults([
  80. 'constraints' => [
  81. new UniqueEntity([
  82. 'entityClass' => User::class,
  83. 'fields' => 'email'
  84. ])
  85. ],
  86. 'data_class' => User::class,
  87. ]);
  88. }
  89. }