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('firstName')
  19.             ->add('lastName')
  20.             ->add('phoneNo')
  21.             ->add('gender')
  22.             //->add('address')
  23.             ->add('houseNumber',null, ['mapped' => false])
  24.             ->add('street',null, ['mapped' => false])
  25.             ->add('postCode',null, ['mapped' => false])
  26.             ->add('agreeTerms'CheckboxType::class, [
  27.                 'mapped' => false,
  28.                 'constraints' => [
  29.                     new IsTrue([
  30.                         'message' => 'You should agree to our terms.',
  31.                     ]),
  32.                 ],
  33.             ])
  34.             ->add('plainPassword'PasswordType::class, [
  35.                 // instead of being set onto the object directly,
  36.                 // this is read and encoded in the controller
  37.                 'mapped' => false,
  38.                 'attr' => ['autocomplete' => 'new-password'],
  39.                 'constraints' => [
  40.                     new NotBlank([
  41.                         'message' => 'Please enter a password',
  42.                     ]),
  43.                     new Length([
  44.                         'min' => 6,
  45.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  46.                         // max length allowed by Symfony for security reasons
  47.                         'max' => 4096,
  48.                     ]),
  49.                 ],
  50.             ])
  51.         ;
  52.     }
  53.     public function configureOptions(OptionsResolver $resolver): void
  54.     {
  55.         $resolver->setDefaults([
  56.             'data_class' => User::class,
  57.         ]);
  58.     }
  59. }