Symfony2形式获取值数组

时间:2016-08-01 11:49:35

标签: php symfony2-forms

当我尝试从我的表单中读取数据时,我遇到了一个小问题

#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>';
            }
         }
 }

当我标记“scolarisé”和“紧张”时,我得到了这个结果:

string(7) "enfant2"

string(7) "enfant4"

非常感谢您的帮助

编辑 我认为形式的枝条:

{% 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 %}

0 个答案:

没有答案