src/Form/ParticulierType.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Gouvernorat;
  4. use App\Entity\Particulier;
  5. use App\Validator\Constraints\PasswordPolicy;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  9. use Symfony\Component\Validator\Constraints\IsTrue;
  10. use Symfony\Component\Validator\Constraints\Length;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Form\Extension\Core\Type\TextType;
  14. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  15. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  16. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  19. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  20. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  21. class ParticulierType extends AbstractType
  22. {
  23.     public function buildForm(FormBuilderInterface $builder, array $options): void
  24.     {
  25.         $builder
  26.             ->add('email'EmailType::class, ['label' => 'inscription.particulier.email''required' => true'constraints' => [
  27.                 new NotBlank([
  28.                     'message' => 'Ce champs est obligatoire',
  29.                 ]),
  30.             ],], array('attr' => array('class' => 'form-control left-line')))
  31.             ->add('username'TextType::class, ['label' => 'inscription.particulier.username''required' => true'constraints' => [
  32.                 new NotBlank([
  33.                     'message' => 'Ce champs est obligatoire',
  34.                 ]),
  35.             ],], array('attr' => array('class' => 'form-control left-line')))
  36.             ->add('plainPassword'PasswordType::class, [
  37.                 // instead of being set onto the object directly,
  38.                 // this is read and encoded in the controller
  39.                 'label' => 'inscription.particulier.password',
  40.                 'mapped' => false,
  41.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-style password1'],                'constraints' => [
  42.                     new NotBlank([
  43.                         'message' => 'Veuillez saisir un mot de passe.',
  44.                     ]),
  45.                     new PasswordPolicy(),
  46.                 ],
  47.             ])
  48.             ->add('confirmpassword'PasswordType::class, [
  49.                 // instead of being set onto the object directly,
  50.                 // this is read and encoded in the controller
  51.                 'label' => 'inscription.particulier.confirm_pass',
  52.                 'mapped' => false,
  53.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-style password2'],
  54.                 'constraints' => [
  55.                     new Length([
  56.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  57.                         // max length allowed by Symfony for security reasons
  58.                         'max' => 4096,
  59.                     ]),
  60.                 ],
  61.             ])
  62.             ->add('nom'TextType::class, ['label' => 'inscription.particulier.lastname''required' => true'constraints' => [
  63.                 new NotBlank([
  64.                     'message' => 'Ce champs est obligatoire',
  65.                 ]),
  66.             ],], array('attr' => array('class' => 'form-control left-line')))
  67.             ->add('prenom'TextType::class, ['label' => 'inscription.particulier.firstname''required' => true'constraints' => [
  68.                 new NotBlank([
  69.                     'message' => 'Ce champs est obligatoire',
  70.                 ]),
  71.             ],], array('attr' => array('class' => 'form-control left-line')))
  72.             ->add('tel'TextType::class, [
  73.                 'label' => 'inscription.particulier.tel',
  74.                 'required' => true,
  75.                 'attr'=> ['min' => 0'pattern'=>'\d{8}''maxlength' => 8'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  76.                  'constraints' => [
  77.                 new NotBlank([
  78.                     'message' => 'Ce champs est obligatoire',
  79.                 ]),
  80.             ],], array('attr' => array('class' => 'form-control left-line')))
  81.             ->add('gouvernorat'EntityType::class, array(
  82.                 'class'=>Gouvernorat::class,
  83.                 'label' => 'inscription.particulier.gov',
  84.                 'choice_label'=>'libelle',
  85.             ))
  86.             ->add('adresse'TextType::class, [
  87.                 'label' => 'inscription.particulier.adresse',
  88.                 'mapped' => false
  89.             ])
  90.             ->add('code_postale'TextType::class, [
  91.                 'label' => 'inscription.particulier.postal_code',
  92.                 'mapped' => false,
  93.                 'attr'=> ['min' => ,'pattern' => '\d{4}''title' => 'Entrez exactement 4 chiffres''maxlength' => 4'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  94.             ])
  95.             ->add('fonction'ChoiceType::class, [
  96.                 'label' => 'inscription.particulier.function',
  97.                 'choices' => [
  98.                     'inscription.particulier.etudiant' => 'Etudiant(e)',
  99.                     'inscription.particulier.fonctionnaire' => 'Fonctionnaire',
  100.                     'inscription.particulier.enseignant_universitaire' => 'Enseignant(e) universitaire',
  101.                     'inscription.particulier.autres' => 'Autres'
  102.                 ],
  103.                 'placeholder' => 'inscription.particulier.choose_function',
  104.                 
  105.             ])
  106.             ->add('fonctions'TextType::class, ['label' => 'Autre fonction ''constraints' => [
  107.                
  108.             ],], array('attr' => array('class' => 'form-control left-line')))
  109.             
  110.             
  111.             ->add('agreeTerms'CheckboxType::class, [
  112.                 'label' => 'inscription.entreprise.terms',
  113.                 'label_html' => true,
  114.                 'mapped' => false,
  115.                 'data_class'=>null,
  116.                 "row_attr" => ['class' => 'accepter_cond'], 'attr' => array('id' => 'accepter_cond'),
  117.                 'constraints' => [
  118.                     new IsTrue([
  119.                         'message' => 'Vous devez accepter nos conditions.',
  120.                     ]),
  121.                 ],
  122.             ])
  123.             ->add(
  124.                 'Enregistrer',
  125.                 SubmitType::class,
  126.                 [
  127.                     'label' => 'inscription.save',
  128.                     'attr' => ['class' => 'save'],
  129.                 ]
  130.             )
  131.         ;
  132.     }
  133.     public function configureOptions(OptionsResolver $resolver): void
  134.     {
  135.         $resolver->setDefaults([
  136.             'data_class' => Particulier::class,
  137.         ]);
  138.     }
  139. }