src/Form/PartenaireRegionalType.php line 29

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