src\Form\RegistrationType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Utilisateur;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\TelType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  10. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Validator\Constraints\Email;
  14. use Symfony\Component\Validator\Constraints\Length;
  15. use Symfony\Component\Validator\Constraints\NotBlank;
  16. use Symfony\Component\Validator\Constraints\Regex;
  17. class RegistrationType extends AbstractType
  18. {
  19. public function buildForm(FormBuilderInterface $builder, array $options)
  20. {
  21. $builder
  22. ->add('email', EmailType::class, [
  23. 'label' => 'Email',
  24. 'attr' => ['placeholder' => 'Email'],
  25. 'required' => true,
  26. 'constraints' => [
  27. new NotBlank([
  28. 'message' => 'Ce champ ne peut être vide'
  29. ]),
  30. new Length([
  31. // max length allowed by Symfony for security reasons
  32. 'max' => 50,
  33. ]),
  34. new Email([
  35. 'message' => 'Veuillez entrer une adresse email valide',
  36. ]),
  37. ],
  38. ])
  39. ->add('password', PasswordType::class, [
  40. 'label' => 'Mot de passe',
  41. 'required' => true,
  42. 'attr' => ['autocomplete' => 'new-password'],
  43. 'constraints' => [
  44. new NotBlank([
  45. 'message' => 'Ce champ ne peut être vide',
  46. ]),
  47. new Length([
  48. 'min' => 10,
  49. 'minMessage' => 'Votre mot de passe doit avoir au moins {{ limit }} caractères',
  50. // max length allowed by Symfony for security reasons
  51. 'max' =>50,
  52. 'maxMessage' => 'Votre mot de passe ne peut pas avoir plus de {{ limit }} caractères',
  53. ]),
  54. new Regex([
  55. 'pattern' => '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&]).+$/',
  56. 'message' => 'Votre mot de passe doit contenir au moins une majuscule, une minuscule, un chiffre et un caractère spécial',
  57. ])
  58. ],
  59. ])
  60. ->add('prenom', TextType::class, [
  61. 'label' => 'Prénom',
  62. 'attr' => ['placeholder' => 'Prénom'],
  63. 'required' => true,
  64. 'constraints' => [
  65. new NotBlank([
  66. 'message' => 'Ce champ ne peut être vide',
  67. ]), new Length([
  68. // max length allowed by Symfony for security reasons
  69. 'max' => 50,
  70. ]),
  71. ],
  72. ])
  73. ->add('nom', TextType::class, [
  74. 'label' => 'Nom',
  75. 'attr' => ['placeholder' => 'Nom'],
  76. 'required' => true,
  77. 'constraints' => [
  78. new NotBlank([
  79. 'message' => 'Ce champ ne peut être vide',
  80. ]), new Length([
  81. // max length allowed by Symfony for security reasons
  82. 'max' => 50,
  83. ]),
  84. ],
  85. ])
  86. ->add('telephone', TelType::class, [
  87. 'label' => 'Téléphone',
  88. 'attr' => ['placeholder' => 'Téléphone'],
  89. 'required' => false,
  90. 'constraints' => [
  91. new Length([
  92. // max length allowed by Symfony for security reasons
  93. 'max' => 50,
  94. ]),
  95. ],
  96. ])
  97. ->add('ville', TextType::class, [
  98. 'label' => 'Ville',
  99. 'attr' => ['placeholder' => 'Ville'],
  100. 'required' => false,
  101. 'constraints' => [
  102. new Length([
  103. // max length allowed by Symfony for security reasons
  104. 'max' => 50,
  105. ]),
  106. ],
  107. ])
  108. ->add('pays', TextType::class, [
  109. 'label' => 'Pays',
  110. 'attr' => ['placeholder' => 'Pays'],
  111. 'required' => false,
  112. 'constraints' => [
  113. new Length([
  114. // max length allowed by Symfony for security reasons
  115. 'max' => 50,
  116. ]),
  117. ],
  118. ])
  119. ->add('adresse_postal', TextareaType::class, [
  120. 'label' => 'Adresse postale',
  121. 'attr' => ['placeholder' => 'Adresse postale'],
  122. 'required' => false,
  123. 'constraints' => [
  124. new Length([
  125. // max length allowed by Symfony for security reasons
  126. 'max' => 50,
  127. ]),
  128. ],
  129. ])
  130. ;
  131. // Bouton Envoyer
  132. $builder->add('submit', SubmitType::class, array(
  133. 'label' => 'Enregistrer'
  134. ));
  135. }
  136. public function configureOptions(OptionsResolver $resolver)
  137. {
  138. $resolver->setDefaults([
  139. 'data_class' => Utilisateur::class,
  140. ]);
  141. }
  142. }