src/Form/Builder/RegistrationFormType.php line 13

  1. <?php
  2. namespace App\Form\Builder;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Component\Validator\Constraints\Length;
  9. use Symfony\Component\Validator\Constraints\NotBlank;
  10. class RegistrationFormType extends AbstractType
  11. {
  12.     public function buildForm(FormBuilderInterface $builder, array $options): void
  13.     {
  14.         $builder
  15.             ->add('email')
  16.             ->add('username')
  17. //            ->add('agreeTerms', CheckboxType::class, [
  18. //                'mapped' => false,
  19. //                'constraints' => [
  20. //                    new IsTrue([
  21. //                        'message' => 'You should agree to our terms.',
  22. //                    ]),
  23. //                ],
  24. //            ])
  25.             ->add('plainPassword'PasswordType::class, [
  26.                 'mapped' => false,
  27.                 'attr' => ['autocomplete' => 'new-password'],
  28.                 'constraints' => [
  29.                     new NotBlank([
  30.                         'message' => 'Please enter a password',
  31.                     ]),
  32.                     new Length([
  33.                         'min' => 6,
  34.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  35.                         // max length allowed by Symfony for security reasons
  36.                         'max' => 4096,
  37.                     ]),
  38.                 ],
  39.             ])
  40.         ;
  41.     }
  42.     public function configureOptions(OptionsResolver $resolver): void
  43.     {
  44.         $resolver->setDefaults([
  45.             'data_class' => User::class,
  46.         ]);
  47.     }
  48. }