src/Form/RegistrationFormType.php line 19

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  5. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  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. use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordRequirements;
  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_attr' => ['class' => 'uk-form-label'],
  33.                 'attr' => ['class' => 'uk-checkbox uk-margin-left'],
  34.                 'constraints' => [
  35.                     new IsTrue([
  36.                         'message' => 'You should agree to our terms.',
  37.                     ]),
  38.                 ],
  39.             ])
  40.             ->add('plainPassword'PasswordType::class, [
  41.                 // instead of being set onto the object directly,
  42.                 // this is read and encoded in the controller
  43.                 'mapped' => false,
  44.                 'label_attr' => ['class' => 'uk-form-label'],
  45.                 'attr' => ['autocomplete' => 'new-password''class' => 'uk-input'],
  46.                 'constraints' => [
  47.                     new NotBlank([
  48.                         'message' => 'Please enter a password',
  49.                     ]),
  50.                     new Length([
  51.                         'min' => 8,
  52.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  53.                         // max length allowed by Symfony for security reasons
  54.                         'max' => 25,
  55.                     ]),
  56.                     new PasswordRequirements([
  57.                         'requireLetters' => true,
  58.                         'requireCaseDiff' => true,
  59.                         'requireNumbers' => true,
  60.                         'requireSpecialCharacter' => true,
  61.                     ])
  62.                 ],
  63.             ])
  64.             ->add('captcha'Recaptcha3Type::class, [
  65.                 'constraints' => new Recaptcha3(),
  66.                 'action_name' => 'resetpassword',
  67.                 //'script_nonce_csp' => $nonceCSP,
  68.             ])
  69.         ;
  70.     }
  71.     public function configureOptions(OptionsResolver $resolver): void
  72.     {
  73.         $resolver->setDefaults([
  74.             'data_class' => User::class,
  75.         ]);
  76.     }
  77. }