src/Form/RegistrationFormType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use App\Form\Types\ReCaptchaType;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  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. ->add('firstName', TextType::class, [
  22. 'label' => 'First Name',
  23. ])
  24. ->add('lastName', TextType::class, [
  25. 'label' => 'Last Name',
  26. ])
  27. ->add('agreeTerms', CheckboxType::class, [
  28. 'mapped' => false,
  29. 'constraints' => [
  30. new IsTrue([
  31. 'message' => 'You should agree to our terms.',
  32. ]),
  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' => ['autocomplete' => 'new-password'],
  40. 'constraints' => [
  41. new NotBlank([
  42. 'message' => 'Please enter a password',
  43. ]),
  44. new Length([
  45. 'min' => 6,
  46. 'minMessage' => 'Your password should be at least {{ limit }} characters',
  47. // max length allowed by Symfony for security reasons
  48. 'max' => 4096,
  49. ]),
  50. ],
  51. ])
  52. ->add('captcha', ReCaptchaType::class, [
  53. 'mapped' => false,
  54. 'type' => 'invisible' // (invisible, checkbox)
  55. ])
  56. ;
  57. }
  58. public function configureOptions(OptionsResolver $resolver): void
  59. {
  60. $resolver->setDefaults([
  61. 'data_class' => User::class,
  62. //'error_bubbling' => true
  63. ]);
  64. }
  65. }