src/Form/RegisterType.php line 18

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  9. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  10. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  11. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  12. use Symfony\Component\Validator\Constraints\Regex;
  13. use Symfony\Component\Validator\Constraints\Email;
  14. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  15. class RegisterType extends AbstractType {
  16.     private $tokenStorage;
  17.     public function __construct(TokenStorageInterface $tokenStorage) {
  18.         $this->tokenStorage $tokenStorage;
  19.     }
  20.     public function buildForm(FormBuilderInterface $builder, array $options): void {
  21.         $builder
  22.             ->add('email'TextType::class, [
  23.                 'label' => 'Correo electrónico',
  24.                 'attr' => [
  25.                     'class' => 'form-control',
  26.                     'autocomplete' => 'off',
  27.                     'readonly' => true,
  28.                     'onfocus' => "this.removeAttribute('readonly');"
  29.                 ],
  30.                 'constraints' => new Email([
  31.                     'message' => 'El valor {{ value }} no es un email válido.'// OJO - El valor sale entrecomillado.
  32.                 ]),
  33.             ])
  34.             ->add('password'RepeatedType::class, [
  35.                 'type' => PasswordType::class,
  36.                 'invalid_message' => 'Las contraseñas no coinciden.',
  37.                 'first_options' => [
  38.                     'label' => 'Contraseña',
  39.                     'attr' => [
  40.                         'class' => 'form-control',
  41.                         'autocomplete' => 'off',
  42.                         'readonly' => true,
  43.                         'pattern' => $options['data']['regexp']->getValue(),
  44.                         'onfocus' => "this.removeAttribute('readonly');"
  45.                     ],
  46.                 ],
  47.                 'second_options' => [
  48.                     'label' => 'Repetir contraseña',
  49.                     'attr' => [
  50.                         'class' => 'form-control',
  51.                         'autocomplete' => 'off',
  52.                         'readonly' => true,
  53.                         'pattern' => $options['data']['regexp']->getValue(),
  54.                         'onfocus' => "this.removeAttribute('readonly');"
  55.                     ],
  56.                     'help' => $options['data']['regexp']->getDescription(),
  57.                     'help_html' => true,
  58.                 ],
  59.             ])
  60.             ->add('policyagreed'CheckboxType::class, [
  61.                 'label' => 'Acepto las <a href="http://www.editorialtulibro.es/condiciones-generales-contratacion-servicios-editoriales/">condiciones de contratación</a> y la <a href="http://www.editorialtulibro.es/politica-privacidad/">política de privacidad</a>.',
  62.                 'label_html' => true,
  63.                 'required' => true,
  64.                 'attr' => [
  65.                     'style' => 'float: left;margin-top: 5px;margin-right: 7px;'
  66.                 ]
  67.             ])
  68.             ->add(
  69.                 'submit',
  70.                 SubmitType::class,
  71.                 [
  72.                     'attr' => ['class' => 'btn btn-primary'],
  73.                     'label' => 'Registrarse',
  74.                 ]
  75.             );
  76.     }
  77.     public function configureOptions(OptionsResolver $resolver): void {
  78.         $resolver->setDefaults([
  79.             // 'data_class' => User::class,
  80.         ]);
  81.     }
  82. }