src/Form/RegistrationFormType.php line 20

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\EmailType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  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. use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordRequirements;
  14. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  15. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  16. class RegistrationFormType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options): void
  19.     {
  20.         $builder
  21.             ->add('email'EmailType::class, [
  22.                 'label_attr' => ['class' => 'uk-form-label'],
  23.                 'attr' => ['autocomplete' => 'email''class' => 'uk-input'],
  24.                 'constraints' => [
  25.                     new NotBlank([
  26.                         'message' => 'Please enter your email',
  27.                     ]),
  28.                 ],
  29.             ])
  30.             ->add('agreeTerms'CheckboxType::class, [
  31.                 'mapped' => false,
  32.                 'label' => 'I agree to the website\'s <a href="/privacy" target="_blank">Terms & Conditions</a> for creating account.',
  33.                 'label_html' => true,
  34.                 'label_attr' => ['class' => 'uk-form-label'],
  35.                 'attr' => ['class' => 'uk-checkbox uk-margin-small-left'],
  36.                 'constraints' => [
  37.                     new IsTrue([
  38.                         'message' => 'You should agree to our terms.',
  39.                     ]),
  40.                 ],
  41.             ])
  42.             ->add('plainPassword'PasswordType::class, [
  43.                 // instead of being set onto the object directly,
  44.                 // this is read and encoded in the controller
  45.                 'mapped' => false,
  46.                 'label_attr' => ['class' => 'uk-form-label'],
  47.                 'attr' => ['autocomplete' => 'new-password''class' => 'uk-input'],
  48.                 'constraints' => [
  49.                     new NotBlank([
  50.                         'message' => 'Please enter a password',
  51.                     ]),
  52.                     new Length([
  53.                         'min' => 8,
  54.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  55.                         // max length allowed by Symfony for security reasons
  56.                         'max' => 25,
  57.                     ]),
  58.                     new PasswordRequirements([
  59.                         'requireLetters' => true,
  60.                         'requireCaseDiff' => true,
  61.                         'requireNumbers' => true,
  62.                         'requireSpecialCharacter' => true,
  63.                     ])
  64.                 ],
  65.             ])
  66.             ->add('captcha'Recaptcha3Type::class, [
  67.                 'constraints' => new Recaptcha3(),
  68.                 'action_name' => 'register',
  69.                 //'script_nonce_csp' => $nonceCSP,
  70.             ])
  71.         ;
  72.     }
  73.     public function configureOptions(OptionsResolver $resolver): void
  74.     {
  75.         $resolver->setDefaults([
  76.             'data_class' => User::class,
  77.         ]);
  78.     }
  79. }