src/Form/RegistrationFormType.php line 15

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\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('nome')
  18.             ->add('cognome')
  19.             ->add('email')
  20.             ->add('agreeTerms'CheckboxType::class, [
  21.                 'label' => "Accetto la privacy policy",
  22.                 'mapped' => false,
  23.                 'constraints' => [
  24.                     new IsTrue([
  25.                         'message' => 'Devi accettare la privacy policy',
  26.                     ]),
  27.                 ],
  28.             ])
  29.             ->add('plainPassword'PasswordType::class, [
  30.                 // instead of being set onto the object directly,
  31.                 // this is read and encoded in the controller
  32.                 'mapped' => false,
  33.                 'attr' => ['autocomplete' => 'new-password'],
  34.                 'constraints' => [
  35.                     new NotBlank([
  36.                         'message' => 'Inserisci una password',
  37.                     ]),
  38.                     new Length([
  39.                         'min' => 6,
  40.                         'minMessage' => 'La password deve essere di almeno {{ limit }} caratteri',
  41.                         // max length allowed by Symfony for security reasons
  42.                         'max' => 4096,
  43.                     ]),
  44.                 ],
  45.             ]);
  46.     }
  47.     public function configureOptions(OptionsResolver $resolver): void
  48.     {
  49.         $resolver->setDefaults([
  50.             'data_class' => User::class,
  51.         ]);
  52.     }
  53. }