src/Form/Frontend/RegistrationFormType.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Form\Frontend;
  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.     /**
  15.      * @param FormBuilderInterface $builder
  16.      * @param array $options
  17.      *
  18.      * @return void
  19.      */
  20.     public function buildForm(FormBuilderInterface $builder, array $options): void
  21.     {
  22.         $builder
  23.             ->add('email')
  24.             ->add('agreeTerms'CheckboxType::class, [
  25.                 'mapped' => false,
  26.                 'constraints' => [
  27.                     new IsTrue([
  28.                         'message' => 'You should agree to our terms.',
  29.                     ]),
  30.                 ],
  31.             ])
  32.             ->add('plainPassword'PasswordType::class, [
  33.                 'mapped' => false,
  34.                 'attr' => ['autocomplete' => 'new-password'],
  35.                 'constraints' => [
  36.                     new NotBlank(['message' => 'Please enter a password',]),
  37.                     new Length([
  38.                         'min' => 6,
  39.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  40.                         'max' => 4096,
  41.                     ]),
  42.                 ],
  43.             ])
  44.         ;
  45.     }
  46.     /**
  47.      * @param OptionsResolver $resolver
  48.      *
  49.      * @return void
  50.      */
  51.     public function configureOptions(OptionsResolver $resolver): void
  52.     {
  53.         $resolver->setDefaults([
  54.             'data_class' => User::class,
  55.         ]);
  56.     }
  57. }