← Back
Editing: ChangePasswordFormType.php
<?php namespace App\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\RepeatedType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; class ChangePasswordFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add( 'plainPassword', RepeatedType::class, [ 'type' => PasswordType::class, 'first_options' => [ 'constraints' => [ new NotBlank( [ 'message' => 'Veuillez entrer un mot de passe', ] ), new Length( [ 'min' => 6, 'minMessage' => 'Votre mot de passe doit contenir au moins {{ limit }} caractères', // max length allowed by Symfony for security reasons 'max' => 4096, ] ), ], 'label' => 'Nouveau mot de passe', 'attr' => ['class' => 'form-control'], ], 'second_options' => [ 'label' => 'Répeter le mot de passe', 'attr' => ['class' => 'form-control'], ], 'invalid_message' => 'The password fields must match.', // Instead of being set onto the object directly, // this is read and encoded in the controller 'mapped' => false, ] ); } public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([]); } }
Save File
Cancel