<?php
namespace App\Form;
use App\Entity\Pays;
use App\Entity\User;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
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\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Validator\Constraints\Unique;
class RegistrationFormType extends AbstractType
{
public $classAttr=['class'=>'h-lg'];
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nom',TextType::class,[
'label'=>"Nom de famille",
'attr'=>$this->classAttr,
]
)
->add('prenom',TextType::class,
[
'label'=>"Prénom",
'attr'=>$this->classAttr,
]
)
->add('tel',TelType::class,[
'label'=>"Numéro de téléphone",
'attr'=>$this->classAttr,
]
)
->add('civilite',ChoiceType::class,
[
'label'=>"Civilité",
'attr'=>$this->classAttr,
'choices' => $this->getCivilites()
]
) ->add('pays',EntityType::class,
[
'label'=>"Pays",
'class' => Pays::class,
'choice_label' => 'nompays',
'attr'=>$this->classAttr,
]
)
->add('email',EmailType::class,[
'label' => 'Adresse Email',
'attr'=>$this->classAttr,
'constraints'=>[
new Email([
'message' => 'Veuillez entrer une adresse Email valide',
]),
/*new Unique([
'message'=>'Cette adresse Email existe déjà'
])*/
]
])/*
->add('agreeTerms', CheckboxType::class, [
'label' => "J'accepte les conditions d'utilisation",
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'Vous devez accepter les conditions d\'utilisation.',
]),
],
])*/
->add('plainPassword', RepeatedType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'attr'=>$this->classAttr,
'type' => PasswordType::class,
'first_options' => array('label' => 'Mot de passe'),
'second_options' => array('label' => 'confirmer mot de passe'),
'invalid_message' => 'Veuillez entrer les mêmes mot de passe',
'mapped' => false,
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Votre mot de passe doit comporter au moins {{ limit }} caractères',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
//---
private function getCivilites(){
$temp_civilites=[];
foreach (User::civilites_long AS $key=>$value){
$temp_civilites[$value] = $key;
}
return $temp_civilites;
}
}