src/Form/RegistrationFormType.php line 15

Open in your IDE?
  1. <?php
  2. // src/Form/RegistrationFormType.php
  3. namespace App\Form;
  4. use App\Entity\User;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  9. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. class RegistrationFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('email'EmailType::class, [
  19.                 'constraints' => [
  20.                     new Assert\NotBlank(),
  21.                     new Assert\Email(),
  22.                 ],
  23.             ])
  24.             ->add('plainPassword'RepeatedType::class, [
  25.                 'type' => PasswordType::class,
  26.                 'first_options' => ['label' => 'Password'],
  27.                 'second_options' => ['label' => 'Repeat Password'],
  28.                 'constraints' => [
  29.                     new Assert\NotBlank(),
  30.                     new Assert\Length(['min' => 6]),
  31.                 ],
  32.             ])
  33.             ->add('agreeTerms'CheckboxType::class, [
  34.                 'mapped' => false,
  35.                 'constraints' => [
  36.                     new Assert\IsTrue(),
  37.                 ],
  38.             ]);
  39.     }
  40.     public function configureOptions(OptionsResolver $resolver): void
  41.     {
  42.         $resolver->setDefaults([
  43.             'data_class' => User::class,
  44.         ]);
  45.     }
  46. }