0

I have a small problem while i'm trying to read data from my form

#ProblemePersonneType.php#

 ->add("enfants",'choice', array('choices' => array( 'enfant1'=>"CAF",
                                                     'enfant2'=>"Scolarisé",
                                                     'enfant3'=>"Formation",
                                                     'enfant4'=>"Tension",
                                                     'enfant5'=>"Violence",
                                                     'enfant6'=>"Signalement",
                                                     'enfant7'=>"ASE",
                                                     'enfant8'=>"PJJ",
                                                     'enfant9'=>"Autres"),

                        'required' => false,
                        'expanded'=>true,
                        'multiple'=>true))

#ProblemeController.php#

 foreach ($form->getData() as $probleme){
        if($probleme !=0){
            foreach ($probleme as $type){
                echo '<pre>';
                var_dump($type);
                echo '</pre>';
            }
         }
 }

When i mark "scolarisé" and "tension" I got this result :

string(7) "enfant2"

string(7) "enfant4"

Thank you very much for your help

Edit My view twig of form:

{% extends '::base.html.twig' %}

{% block body %}
    <form action="{{ path('application_ajouterProbleme', {'id': 2}) }}" method="POST">
        <div class="form-inline">
            {{ form_row(form.couple) }}
            {{ form_row(form.handicape) }}
        </div>
        <br>
        <div class="form-inline">
            {{ form_row(form.enfants) }}
        </div>
        <br>
        <div class="form-inline">
            {{ form_row(form.hebergement) }}
        </div>
        <br>
        <div class="form-inline">
            {{ form_row(form.emploi_et_revenus) }}
        </div>
        <br>
        <div class="form-inline">
            {{ form_row(form.sante) }}
            {{ form_row(form.amendes) }}
        </div>

        <div class="form-inline">
            {{ form_row(form.citoyennete) }}
            {{ form_row(form.consommation) }}
        </div>
        <br>
        <div class="form-inline">
            {{ form_widget(form.ajouter_probleme) }}
        </div>
    </form>
{% endblock %}
  • Don't quite get it? Can you explain a little further – jonju Aug 01 '16 at 11:52
  • What I want to do is to go through my table and if I got a cell that is marked, I want to get the key and the value to save them in my database. Example : if I mark the first cell, I'll get "enfant1" as key and "CAF" as value and once I'll get that, i'll be able to save them. I hope I'm clear enough, sorry for any mistake, I don't speak english very often. – Robert Muputou Khalina Aug 01 '16 at 13:10
  • Forgive me but I still don't get all of it. `table' ?? `marked` ?? these are quite confusing – jonju Aug 01 '16 at 13:29
  • Table is the array: `array( 'enfant1'=>"CAF",'enfant2'=>"Scolarisé", 'enfant3'=>"Formation",enfant4'=>"Tension",'enfant5'=>"Violence",'enfant6'=>"Signalement",'enfant7'=>"ASE",'enfant8'=>"PJJ",'enfant9'=>"Autres")` Marked means that the box is checked I found some informations on what i want to do, and i think i have to get the label only – Robert Muputou Khalina Aug 02 '16 at 13:30
  • Can you add your View(twig) in question? – jonju Aug 02 '16 at 13:56
  • I edit the post , you can see my view in the message – Robert Muputou Khalina Aug 03 '16 at 17:50

0 Answers0