src/Form/RegistrationFormType.php line 15

  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\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Validator\Constraints\IsTrue;
  10. use Symfony\Component\Validator\Constraints\Length;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. class RegistrationFormType extends AbstractType
  13. {
  14.     public function buildForm(FormBuilderInterface $builder, array $options): void
  15.     {
  16.         $builder
  17.             ->add('email')
  18. //            ->add('agreeTerms', CheckboxType::class, [
  19. //                'mapped' => false,
  20. //                'constraints' => [
  21. //                    new IsTrue([
  22. //                        'message' => 'You should agree to our terms.',
  23. //                    ]),
  24. //                ],
  25. //            ])
  26.             ->add('plainPassword'PasswordType::class, [
  27.                 // instead of being set onto the object directly,
  28.                 // this is read and encoded in the controller
  29.                 'mapped' => false,
  30.                 'attr' => ['autocomplete' => 'new-password'],
  31.                 'constraints' => [
  32.                     new NotBlank([
  33.                         'message' => 'Please enter a password',
  34.                     ]),
  35.                     new Length([
  36.                         'min' => 6,
  37.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  38.                         // max length allowed by Symfony for security reasons
  39.                         'max' => 4096,
  40.                     ]),
  41.                 ],
  42.             ])
  43.         ;
  44.     }
  45.     public function configureOptions(OptionsResolver $resolver): void
  46.     {
  47.         $resolver->setDefaults([
  48.             'data_class' => User::class,
  49.         ]);
  50.     }
  51. }