src/Form/LoginFormType.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  5. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Component\Validator\Constraints\Length;
  9. use Symfony\Component\Validator\Constraints\NotBlank;
  10. class LoginFormType extends AbstractType
  11. {
  12.     public function buildForm(FormBuilderInterface $builder, array $options): void
  13.     {
  14.         $builder
  15.             ->add('handle')
  16.             ->add('password'PasswordType::class, [
  17.                 'constraints' => [
  18.                     new NotBlank([
  19.                         'message' => 'Please enter a password',
  20.                     ]),
  21.                     new Length([
  22.                         'min' => 8,
  23.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  24.                         // max length allowed by Symfony for security reasons
  25.                         'max' => 4096,
  26.                     ]),
  27.                 ],
  28.             ])
  29.             ->add('submit'SubmitType::class, [
  30.                 'label' => 'Login'
  31.             ]);
  32.     }
  33.     public function configureOptions(OptionsResolver $resolver): void
  34.     {
  35.         $resolver->setDefaults([
  36.             'csrf_protection' => true,
  37.             'csrf_field_name' => 'csrf_token',
  38.             'csrf_token_id'   => 'authenticate',
  39.         ]);
  40.     }
  41. }