src\Form\RegistrationFormType.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Pays;
  4. use App\Entity\User;
  5. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\Email;
  12. use Symfony\Component\Validator\Constraints\IsTrue;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  16. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextType;
  18. use Symfony\Component\Form\Extension\Core\Type\TelType;
  19. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  20. use Symfony\Component\Validator\Constraints\Unique;
  21. class RegistrationFormType extends AbstractType
  22. {
  23.     public $classAttr=['class'=>'h-lg'];
  24.     public function buildForm(FormBuilderInterface $builder, array $options)
  25.     {
  26.         $builder
  27.             ->add('nom',TextType::class,[
  28.                 'label'=>"Nom de famille",
  29.                 'attr'=>$this->classAttr,
  30.                 ]
  31.             )
  32.             ->add('prenom',TextType::class,
  33.                 [
  34.                     'label'=>"Prénom",
  35.                     'attr'=>$this->classAttr,
  36.                 ]
  37.             )
  38.             ->add('tel',TelType::class,[
  39.                 'label'=>"Numéro de téléphone",
  40.                 'attr'=>$this->classAttr,
  41.                 ]
  42.             )
  43.             ->add('civilite',ChoiceType::class,
  44.                 [
  45.                     'label'=>"Civilité",
  46.                     'attr'=>$this->classAttr,
  47.                     'choices' => $this->getCivilites()
  48.                 ]
  49.             ) ->add('pays',EntityType::class,
  50.                 [
  51.                     'label'=>"Pays",
  52.                     'class' => Pays::class,
  53.                     'choice_label' => 'nompays',
  54.                     'attr'=>$this->classAttr,
  55.                 ]
  56.             )
  57.             ->add('email',EmailType::class,[
  58.                 'label' => 'Adresse Email',
  59.                 'attr'=>$this->classAttr,
  60.                 'constraints'=>[
  61.                     new Email([
  62.                         'message' => 'Veuillez entrer une adresse Email valide',
  63.                     ]),
  64.                     /*new Unique([
  65.                         'message'=>'Cette adresse Email existe déjà'
  66.                     ])*/
  67.                 ]
  68.             ])/*
  69.             ->add('agreeTerms', CheckboxType::class, [
  70.                 'label' => "J'accepte les conditions d'utilisation",
  71.                 'mapped' => false,
  72.                 'constraints' => [
  73.                     new IsTrue([
  74.                         'message' => 'Vous devez accepter les conditions d\'utilisation.',
  75.                     ]),
  76.                 ],
  77.             ])*/
  78.             ->add('plainPassword'RepeatedType::class, [
  79.                 // instead of being set onto the object directly,
  80.                 // this is read and encoded in the controller
  81.                 'attr'=>$this->classAttr,
  82.                 'type' => PasswordType::class,
  83.                 'first_options'  => array('label' => 'Mot de passe'),
  84.                 'second_options' => array('label' => 'confirmer mot de passe'),
  85.                 'invalid_message' => 'Veuillez entrer les mêmes mot de passe',
  86.                 'mapped' => false,
  87.                 'constraints' => [
  88.                     new NotBlank([
  89.                         'message' => 'Please enter a password',
  90.                     ]),
  91.                     new Length([
  92.                         'min' => 6,
  93.                         'minMessage' => 'Votre mot de passe doit comporter au moins {{ limit }} caractères',
  94.                         // max length allowed by Symfony for security reasons
  95.                         'max' => 4096,
  96.                     ]),
  97.                 ],
  98.             ])
  99.         ;
  100.     }
  101.     public function configureOptions(OptionsResolver $resolver)
  102.     {
  103.         $resolver->setDefaults([
  104.             'data_class' => User::class,
  105.         ]);
  106.     }
  107.     //---
  108.     private function getCivilites(){
  109.         $temp_civilites=[];
  110.         foreach (User::civilites_long AS $key=>$value){
  111.             $temp_civilites[$value] = $key;
  112.         }
  113.         return $temp_civilites;
  114.     }
  115. }