src/Form/RegistrationFormType.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form;
  4. use App\Entity\User;
  5. use App\Form\Type\CountryPhoneType;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  10. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Validator\Constraints\IsTrue;
  14. use Symfony\Component\Validator\Constraints\Length;
  15. use Symfony\Component\Validator\Constraints\NotBlank;
  16. class RegistrationFormType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options): void
  19.     {
  20.         $builder
  21.             ->add('email'EmailType::class, [
  22.                 'label' => 'E-mail'
  23.             ])
  24.             ->add('phone'CountryPhoneType::class, [
  25.                 'label' => 'Cell phone',
  26.                 'preferred_choices' => [48494434],
  27.             ])
  28.             ->add('plainPassword'RepeatedType::class, [
  29.                 'type' => PasswordType::class,
  30.                 'invalid_message' => 'pages.user.profileEdit.form.validation.password.repeatMatch',
  31.                 'options' => ['attr' => ['autocomplete' => 'new-password']],
  32.                 'required' => false,
  33.                 'first_options' => ['label' => 'pages.user.profileEdit.form.password.first'],
  34.                 'second_options' => ['label' => 'pages.user.profileEdit.form.password.repeat'],
  35.                 'mapped' => false,
  36.                 'attr' => ['autocomplete' => 'new-password'],
  37.                 'constraints' => [
  38.                         new NotBlank(['message' => 'pages.user.profileEdit.form.validation.password.minLength']),
  39.                         new Length([
  40.                             'min' => 6,
  41.                             'minMessage' => 'pages.user.profileEdit.form.validation.password.minLength',
  42.                             'max' => 4096,
  43.                         ]),
  44.                 ],
  45.             ])
  46.             ->add('termsAccepted'CheckboxType::class, [
  47.                 'required' => true,
  48.                 'mapped' => false,
  49.                 'constraints' => [
  50.                     new NotBlank([
  51.                         'message' => "pages.user.register.form.validation.terms"
  52.                     ]),
  53.                 ],
  54.             ])
  55.         ;
  56.     }
  57.     public function configureOptions(OptionsResolver $resolver): void
  58.     {
  59.         $resolver->setDefaults([
  60.             'data_class' => User::class,
  61.             'validation_groups' => ['Default''Registration'],
  62.         ]);
  63.     }
  64. }