src/Form/RegistrationFormType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Account;
  4. use App\Entity\Plan;
  5. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  6. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Form\AbstractType;
  9. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  10. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  11. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. use Symfony\Component\Validator\Constraints\IsTrue;
  16. use Symfony\Component\Validator\Constraints\Length;
  17. use Symfony\Component\Validator\Constraints\NotBlank;
  18. class RegistrationFormType extends AbstractType
  19. {
  20.     public function buildForm(FormBuilderInterface $builder, array $options)
  21.     {
  22.         $builder
  23.             ->add('email'TextType::class, [
  24.                 'label' => 'E-Mail Address',
  25.                 'help' => 'Example: you@yourdomain.com',
  26.                 'attr' => ['placeholder' => 'E-mail address']
  27.             ])
  28.             ->add('name'TextType::class, [
  29.                 'mapped' => false,
  30.                 'attr' => ['placeholder' => 'Your name'],
  31.                 'help' => 'Ex: Hank Aaron',
  32.                 'constraints' => [
  33.                     new NotBlank([
  34.                         'message' => 'Please enter your name',
  35.                     ]),
  36.                     new Length([
  37.                         'min' => 6,
  38.                         'minMessage' => 'Your name cannot be more than {{ limit }} characters',
  39.                         // max length allowed by Symfony for security reasons
  40.                         'max' => 255,
  41.                     ]),
  42.                 ]
  43.             ])
  44.             ->add('captcha'Recaptcha3Type::class, [
  45.                 'constraints' => new Recaptcha3(['message' => 'There were problems with your captcha. Please try again or contact with support and provide following code(s): {{ errorCodes }}']),
  46.                 'action_name' => 'registration'
  47.             ])
  48.             ->add('plainPassword'PasswordType::class, [
  49.                 // instead of being set onto the object directly,
  50.                 // this is read and encoded in the controller
  51.                 'mapped' => false,
  52.                 'attr' => ['placeholder' => 'Password'],
  53.                 'label' => 'Password',
  54.                 'constraints' => [
  55.                     new NotBlank([
  56.                         'message' => 'Please enter a password',
  57.                     ]),
  58.                     new Length([
  59.                         'min' => 6,
  60.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  61.                         // max length allowed by Symfony for security reasons
  62.                         'max' => 4096,
  63.                     ]),
  64.                 ],
  65.             ]);
  66.     }
  67.     public function configureOptions(OptionsResolver $resolver)
  68.     {
  69.         $resolver->setDefaults([
  70.             'data_class' => Account::class,
  71.         ]);
  72.     }
  73. }