src/Form/RegistrationFormType.php line 18
<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class RegistrationFormType extends AbstractType
{
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('userName', null, [
'label' => "Votre nom d'utilisateur",
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer un nom d\'utilisateur',
]),
],
])
->add('email', null, [
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer un email',
]),
new Email([
'message' => 'Veuillez entrer un email valide.',
]),
],
])
->add('agreeTerms', CheckboxType::class, [
'mapped' => false,
'label' => "J'accepte les conditions",
'constraints' => [
new IsTrue([
'message' => 'Vous devez accepter les conditions.',
]),
],
'label' => 'J\'accepte les <a target="_blank" href="'.$this->router->generate('app_conditions_utilisations_show').'">conditions d\'utilisation</a>',
'label_html' => true,
])
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'invalid_message' => 'Les mots de passe doivent correspondre.',
'required' => true,
'first_options' => ['label' => 'Mot de passe'],
'second_options' => ['label' => 'Répétez le mot de passe'],
'constraints' => [
new NotBlank([
'message' => "Merci d'inscrire votre 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,
]),
],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}