src/Form/RegistrationFormType.php line 16

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