src/Form/PartenaireNationalType.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Constants\UploadFileConstraints;
  4. use App\Constants\UploadFileLimit;
  5. use App\Entity\Delegation;
  6. use App\Entity\Partenaire;
  7. use App\Entity\Gouvernorat;
  8. use App\Entity\EnterprisePartenaire;
  9. use App\Validator\Constraints\PasswordPolicy;
  10. use Symfony\Component\Form\AbstractType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  13. use Symfony\Component\Validator\Constraints\IsTrue;
  14. use Symfony\Component\Validator\Constraints\Length;
  15. use Symfony\Component\Validator\Constraints\NotBlank;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. use Symfony\Component\Form\Extension\Core\Type\TextType;
  18. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  19. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  20. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  21. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  22. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  23. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  24. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  25. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  26. use Symfony\Component\Form\Extension\Core\Type\FileType;
  27. class PartenaireNationalType extends AbstractType
  28. {
  29.     public function buildForm(FormBuilderInterface $builder, array $options): void
  30.     {
  31.         $builder
  32.         ->add('email'EmailType::class, ['label' => 'inscription.part_nat.email''required' => true'constraints' => [
  33.             new NotBlank([
  34.                 'message' => 'Ce champs est obligatoire',
  35.             ]),
  36.         ],], array('attr' => array('class' => 'form-control left-line')))
  37.         ->add('username'TextType::class, ['label' => 'inscription.part_nat.username''required' => true'constraints' => [
  38.             new NotBlank([
  39.                 'message' => 'Ce champs est obligatoire',
  40.             ]),
  41.         ],], array('attr' => array('class' => 'form-control left-line')))
  42.             ->add('plainPassword'PasswordType::class, [
  43.                 // instead of being set onto the object directly,
  44.                 // this is read and encoded in the controller
  45.                 'label' => 'inscription.part_nat.password',
  46.                 'mapped' => false,
  47.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-style password1'],
  48.                 'constraints' => [
  49.                     new NotBlank([
  50.                         'message' => 'Veuillez saisir un mot de passe.',
  51.                     ]),
  52.                     new PasswordPolicy(),
  53.                 ],
  54.             ])
  55.             ->add('confirmpassword'PasswordType::class, [
  56.                 // instead of being set onto the object directly,
  57.                 // this is read and encoded in the controller
  58.                 'label' => 'inscription.part_nat.confirm_pass',
  59.                 'mapped' => false,
  60.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-style password2'],
  61.                 'constraints' => [
  62.                     new Length([
  63.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  64.                         // max length allowed by Symfony for security reasons
  65.                         'max' => 4096,
  66.                     ]),
  67.                 ],
  68.             ])
  69.             ->add('nom'TextType::class, ['label' => 'inscription.part_nat.name'], array('attr' => array('class' => 'form-control left-line')))
  70.             ->add('nombre_entreprise'TextType::class, [
  71.                 'label' => 'inscription.part_nat.number',
  72.               //  'mapped' => false,
  73.                 'attr'=> ['min' => 0'pattern'=>'[0-9]+''oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  74.             ])
  75.             ->add('adresse'TextType::class, [
  76.                 'label' => 'inscription.part_nat.adresse',
  77.                 'mapped' => false
  78.             ])
  79.             ->add('gouvernorat'EntityType::class, array(
  80.                 'class'=>Gouvernorat::class,
  81.                 'label' => 'inscription.part_nat.gov',
  82.                 'choice_label'=>'libelle',
  83.                 'choice_translation_domain'=> true,
  84.                 'multiple'=>false,
  85.             ))
  86.             ->add('delegation'EntityType::class, array(
  87.                 'class'=>Delegation::class,
  88.                 'label' => 'inscription.part_nat.delegation',
  89.                 'choice_label'=>'libelle',
  90.                 'choice_translation_domain'=> true,
  91.                 'multiple'=>false,
  92.             ))
  93.             ->add('code_postale'TextType::class, [
  94.                 'label' => 'inscription.part_nat.postal_code',
  95.                 'mapped' => false,
  96.                 'attr'=> ['min' => ,'pattern' => '\d{4}''title' => 'Entrez exactement 4 chiffres''maxlength' => 4'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  97.             ])
  98.             ->add('tel'TextType::class, [
  99.                 'label' => 'inscription.part_nat.tel',
  100.                 'required' => true,
  101.                 'attr'=> ['min' => 0'pattern'=>'\d{8}''maxlength' => 8'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  102.                  'constraints' => [
  103.                 new NotBlank([
  104.                     'message' => 'Ce champs est obligatoire',
  105.                 ]),
  106.             ],], array('attr' => array('class' => 'form-control left-line')))
  107.             ->add('fax'TextType::class, ['label' => 'inscription.part_nat.fax',
  108.             'attr'=> ['min' => 0'pattern' => '\d{8}',  'maxlength' => 8,'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  109.            ]) 
  110.             ->add('nom_prenom_president'TextType::class, ['label' => 'inscription.part_nat.president'])
  111.             ->add('nom_prenom_secretaire_general'TextType::class, ['label' => 'inscription.part_nat.s_generale'])
  112.             ->add('nom_prenom_responsable_UAF'TextType::class, ['label' => 'inscription.part_nat.resp_uaf'])
  113.             ->add('cnsscnrps'ChoiceType::class, [
  114.                 'label' => 'inscription.part_nat.CNSS/CNRPS',
  115.                 'choices' => [
  116.                     'CNSS' => 'CNSS',
  117.                     'CNRPS' => 'CNRPS',
  118.                 
  119.                 ],
  120.                 'placeholder' => 'inscription.part_nat.choose',
  121.                 
  122.             ])
  123.             ->add('code_cnss'TextType::class, ['label' => 'inscription.part_nat.Code_CNSS_Code_CNRPS' 
  124.             ,  'attr'=> [ 'pattern'=>'[0-9]+''oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"]
  125.             ])
  126.             ->add('secteur'TextType::class, ['label' => 'inscription.part_nat.activity_sector'])
  127.             ->add('branche'TextType::class, ['label' => 'inscription.part_nat.activity_branch'])
  128.     
  129.             ->add('enterprisePartenaires'CollectionType::class, array('entry_type' => EnterprisePartenaireType::class,
  130.             'allow_add' => true,
  131.             'allow_delete' => true,
  132.             'form_attr' => 'ok',
  133.             'label' => false,
  134.             'auto_initialize' => false,
  135.             'block_name' => null,
  136.             'compound' => true,
  137.             'by_reference' => false,
  138.             "row_attr" => ['class' => 'form_entreprise_partenaire_national'], 'attr' => array('id' => 'entreprise_partenaire')))
  139.            
  140.             ->add('fileName'FileType::class, [
  141.                 'label' => 'inscription.part_nat.choose_file',
  142.                 'mapped' => false,
  143.                 'required' => false,
  144.                 'constraints' => UploadFileConstraints::document(false),
  145.                 'attr' => [
  146.                     'accept' => 'image/*,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.odt,.ods,.odp',
  147.                     'data-max-size' => UploadFileLimit::MAX_SIZE,
  148.                 ],
  149.             ])
  150.                 
  151.                 ->add('agreeTerms'CheckboxType::class, [
  152.                     'label' => 'inscription.part_nat.terms',
  153.                     'label_html' => true,
  154.                     'mapped' => false,
  155.                     'data_class'=>null,
  156.                     "row_attr" => ['class' => 'accepter_cond'], 'attr' => array('id' => ''),
  157.                     'constraints' => [
  158.                         new IsTrue([
  159.                             'message' => 'Vous devez accepter nos conditions.',
  160.                         ]),
  161.                     ],
  162.                 ])
  163.  
  164.                 ->add(
  165.                     'Enregistrer',
  166.                     SubmitType::class,
  167.                     [
  168.                         'label' => 'inscription.save',
  169.                         'attr' => ['class' => 'save'],
  170.     
  171.                     ]
  172.                     );
  173.     }
  174.     public function configureOptions(OptionsResolver $resolver): void
  175.     {
  176.         $resolver->setDefaults([
  177.             'data_class' => Partenaire::class,
  178.         ]);
  179.     }
  180. }