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.            
  31.                 'required'   => true,
  32.                 'attr' => [ 'placeholder' => 'Phone number','autocomplete' => 'valid-phone-number'],
  33.                 'constraints' => [
  34.                     new NotBlank([
  35.                         'message' => 'Please enter your phone number.',
  36.                     ])
  37.                     ],
  38.             ])
  39.             ->add('plainPassword'PasswordType::class, [
  40.                 // instead of being set onto the object directly,
  41.                 // this is read and encoded in the controller
  42.                 'mapped' => false,
  43.                 'attr' => ['autocomplete' => 'new-password','id' => 'check' ],
  44.                 'constraints' => [
  45.                     new NotBlank([
  46.                         'message' => 'Please enter a password',
  47.                     ]),
  48.                     new Length([
  49.                         'min' => 8,
  50.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  51.                         // max length allowed by Symfony for security reasons
  52.                         'max' => 255,
  53.                     ]),
  54.                     new Regex([
  55.                         'pattern' =>"/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$/",
  56.                         'message' => "Use 1 upper case letter, 1 lower case letter, and 1 number",
  57.                     ])
  58.                 ],
  59.             ])
  60.             ->add('submit'SubmitType::class, [
  61.                 'attr' => ['class' => 'btn btn-lg btn-primary btn-login  btn-blue fw-bold text-uppercase'],
  62.             ]);
  63.         ;
  64.     }
  65.     public function configureOptions(OptionsResolver $resolver): void
  66.     {
  67.         $resolver->setDefaults([
  68.             'data_class' => User::class,
  69.         ]);
  70.     }
  71. }