src/Form/RegistrationFormType.php line 18

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\FormBuilderInterface;
  6. use Symfony\Component\Validator\Constraints\Regex;
  7. use Symfony\Component\Validator\Constraints\IsTrue;
  8. use Symfony\Component\Validator\Constraints\Length;
  9. use Symfony\Component\Validator\Constraints\NotBlank;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  13. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  14. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  15. class RegistrationFormType extends AbstractType
  16. {
  17. public function buildForm(FormBuilderInterface $builder, array $options): void
  18. {
  19. $builder
  20. ->add('email')
  21. ->add('agreeTerms', CheckboxType::class, [
  22. 'mapped' => false,
  23. 'constraints' => [
  24. new IsTrue([
  25. 'message' => 'You should agree to our terms.',
  26. ]),
  27. ],
  28. ])
  29. ->add('phoneNumber', TextType::class,[
  30. 'required' => true,
  31. 'attr' => [ 'placeholder' => 'Phone number','autocomplete' => 'valid-phone-number'],
  32. 'constraints' => [
  33. new NotBlank([
  34. 'message' => 'Please enter your phone number.',
  35. ])
  36. ],
  37. ])
  38. ->add('plainPassword', PasswordType::class, [
  39. // instead of being set onto the object directly,
  40. // this is read and encoded in the controller
  41. 'mapped' => false,
  42. 'attr' => ['autocomplete' => 'new-password','id' => 'check' ],
  43. 'constraints' => [
  44. new NotBlank([
  45. 'message' => 'Please enter a password',
  46. ]),
  47. new Length([
  48. 'min' => 8,
  49. 'minMessage' => 'Your password should be at least {{ limit }} characters',
  50. // max length allowed by Symfony for security reasons
  51. 'max' => 255,
  52. ]),
  53. new Regex([
  54. 'pattern' =>"/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$/",
  55. 'message' => "Use 1 upper case letter, 1 lower case letter, and 1 number",
  56. ])
  57. ],
  58. ])
  59. ->add('submit', SubmitType::class, [
  60. 'attr' => ['class' => 'btn btn-lg btn-primary btn-login btn-blue fw-bold text-uppercase'],
  61. ]);
  62. ;
  63. }
  64. public function configureOptions(OptionsResolver $resolver): void
  65. {
  66. $resolver->setDefaults([
  67. 'data_class' => User::class,
  68. ]);
  69. }
  70. }