src/Form/RegistrationFormType.php line 17

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\PasswordType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Validator\Constraints\IsTrue;
  10. use Symfony\Component\Validator\Constraints\Length;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use VictorPrdh\RecaptchaBundle\Form\ReCaptchaType;
  13. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  14. class RegistrationFormType extends AbstractType
  15. {
  16. public function buildForm(FormBuilderInterface $builder, array $options): void
  17. {
  18. $builder
  19. ->add('email',null,['attr' => ['class'=>'form-control'],])
  20. ->add('agreeTerms', CheckboxType::class, [
  21. 'label' => 'Je reconnais avoir lu et accepté les <a href="/conditions-de-vente.html" style="color:#FFF;font-weight: bold;"> Conditions Générales d\'Inscription</a>',
  22. 'mapped' => false,
  23. 'label_html' => true,
  24. 'constraints' => [
  25. new IsTrue([
  26. 'message' => 'You should agree to our terms.',
  27. ]),
  28. ],
  29. ])
  30. ->add('hasOptin',null,[
  31. 'label' => 'Je souhaite recevoir la Newsletter Croq\'Vacances '
  32. ])
  33. ->add("recaptcha", ReCaptchaType::class)
  34. ->add('plainPassword', PasswordType::class, [
  35. // instead of being set onto the object directly,
  36. // this is read and encoded in the controller
  37. 'mapped' => false,
  38. 'label' => 'Mot de passe',
  39. 'attr' => ['autocomplete' => 'new-password','class'=>'form-control'],
  40. 'constraints' => [
  41. new NotBlank([
  42. 'message' => 'Please enter a password',
  43. ]),
  44. new Length([
  45. 'min' => 8,
  46. 'minMessage' => 'Votre mot de passe doit être composé d\'au moins 8 caractères',
  47. // max length allowed by Symfony for security reasons
  48. 'max' => 4096,
  49. ]),
  50. ],
  51. ])->add('csrf_token', HiddenType::class, [
  52. 'mapped' => false,
  53. 'data' => $options['csrf_token'],
  54. ])
  55. ;
  56. }
  57. public function configureOptions(OptionsResolver $resolver): void
  58. {
  59. $resolver->setDefaults([
  60. 'data_class' => User::class,
  61. 'csrf_protection' => false,
  62. 'csrf_token' => null,
  63. ]);
  64. }
  65. }