src/Form/RegistrationFormType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Institution;
  4. use App\Entity\User;
  5. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  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\NumberType;
  10. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  11. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. use Symfony\Component\Validator\Constraints\IsTrue;
  16. use Symfony\Component\Validator\Constraints\Length;
  17. use Symfony\Component\Validator\Constraints\NotBlank;
  18. class RegistrationFormType extends AbstractType
  19. {
  20.     public function buildForm(FormBuilderInterface $builder, array $options): void
  21.     {
  22.         $builder
  23.             ->add('email'EmailType::class, [
  24.                 'attr' => ['class' => 'form-control form-control-user''placeholder' => 'login.email_required'],
  25.                 'label' => false,
  26.             ])
  27.             // ->add('agreeTerms', CheckboxType::class, [
  28.             //     'mapped' => false,
  29.             //     'constraints' => [
  30.             //         new IsTrue([
  31.             //             'message' => 'You should agree to our terms.',
  32.             //         ]),
  33.             //     ],
  34.             // ])
  35.             ->add('plainPassword'RepeatedType::class, [
  36.                 // instead of being set onto the object directly,
  37.                 // this is read and encoded in the controller
  38.                 'type' => PasswordType::class,
  39.                 'mapped' => false,
  40.                 'attr' => ['autocomplete' => 'new-password'],
  41.                 'constraints' => [
  42.                     new NotBlank([
  43.                         'message' => 'Please enter a password',
  44.                     ]),
  45.                     new Length([
  46.                         'min' => 6,
  47.                         'minMessage' => 'La contraseƱa debe tener al menos {{ limit }} caracteres',
  48.                         // max length allowed by Symfony for security reasons
  49.                         'max' => 4096,
  50.                     ]),
  51.                 ],
  52.                 'invalid_message' => 'La contraseƱa no coincide.',
  53.                 // 'options' => ['attr' => ['class' => 'form-control form-control-user']],
  54.                 'required' => true,
  55.                 'first_options'  => [
  56.                     'attr' => ['class' => 'form-control form-control-user''placeholder' => 'login.password_required'],
  57.                     'label' => false
  58.                 ],
  59.                 'second_options' => [
  60.                     'attr' => ['class' => 'form-control form-control-user''placeholder' => 'login.repeat_password'],
  61.                     'label' => false
  62.                 ],
  63.             ])
  64.             ->add('name'TextType::class, [
  65.                 'attr' => [
  66.                     'class' => 'form-control form-control-user',
  67.                     'placeholder' => 'login.name',
  68.                     'maxlength' => 20,
  69.                 ],
  70.                 'label' => false,
  71.                 'required' => false,
  72.                 'empty_data' => ''
  73.             ])
  74.             ->add('surname'TextType::class, [
  75.                 'attr' => [
  76.                     'class' => 'form-control form-control-user',
  77.                     'placeholder' => 'login.surname',
  78.                     'maxlength' => 50,
  79.                 ],
  80.                 'label' => false,
  81.                 'required' => false,
  82.                 'empty_data' => ''
  83.             ])
  84.             ->add('institution'EntityType::class, [
  85.                 'class' => Institution::class,
  86.                 'attr' => ['class' => 'form-control''maxlength' => 11,],
  87.                 'label' => 'login.entity',
  88.             ])
  89.             ->add('dni'TextType::class, [
  90.                 'attr' => [
  91.                     'class' => 'form-control form-control-user',
  92.                     'placeholder' => 'login.identity',
  93.                     'maxlength' => 20,
  94.                 ],
  95.                 'label' => false,
  96.             ])
  97.             ->add('telephone'NumberType::class, [
  98.                 'attr' => [
  99.                     'class' => 'form-control form-control-user',
  100.                     'placeholder' => 'login.telf',
  101.                     'maxlength' => 50,
  102.                 ],
  103.                 'label' => false,
  104.                 'required' => false,
  105.                 'empty_data' => ''
  106.             ])
  107.             ->add('address'TextType::class, [
  108.                 'attr' => [
  109.                     'class' => 'form-control form-control-user',
  110.                     'placeholder' => 'login.address',
  111.                     'maxlength' => 255,
  112.                 ],
  113.                 'label' => false,
  114.                 'required' => false,
  115.                 'empty_data' => ''
  116.             ])
  117.             ->add('zip_code'TextType::class, [
  118.                 'attr' => [
  119.                     'class' => 'form-control form-control-user',
  120.                     'placeholder' => 'login.zip_code',
  121.                     'maxlength' => 255,
  122.                 ],
  123.                 'label' => false,
  124.                 'required' => false,
  125.             ])
  126.             ->add('country'TextType::class, [
  127.                 'attr' => [
  128.                     'class' => 'form-control form-control-user',
  129.                     'placeholder' => 'login.country',
  130.                     'maxlength' => 255,
  131.                 ],
  132.                 'label' => false,
  133.                 'required' => false,
  134.             ])
  135.             ->add('city'TextType::class, [
  136.                 'attr' => [
  137.                     'class' => 'form-control form-control-user',
  138.                     'placeholder' => 'login.city',
  139.                     'maxlength' => 255,
  140.                 ],
  141.                 'label' => false,
  142.                 'required' => false,
  143.             ])
  144.             ->add('province'TextType::class, [
  145.                 'attr' => [
  146.                     'class' => 'form-control form-control-user',
  147.                     'placeholder' => 'login.province',
  148.                     'maxlength' => 255,
  149.                 ],
  150.                 'label' => false,
  151.                 'required' => false,
  152.             ])
  153.         ;
  154.     }
  155.     public function configureOptions(OptionsResolver $resolver): void
  156.     {
  157.         $resolver->setDefaults([
  158.             'data_class' => User::class,
  159.         ]);
  160.     }
  161. }