src/Form/RegistrationFormType.php line 16

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