0

我有一个只有一个选择标签的表单。当用户提交表单时,我想在我的控制器中获取所选选项标签的 id。我的表格是

 <div class="one_third">
        <form name="portfolios" action="{{ path('MunichInnovationGroupBundle_portfolio') }}" method="post" >
            <h2>Select your portfolio</h2>
            <p>Change the portfolio to be managed:<br />
                <select name="portfolio" style="width: 265px; height:28px;">
                    <option selected="selected" value="default">Switch Your Portfolio</option>
                    {% for portfolio in portfolios %}
                        <option id={{ portfolio.id }}>{{ portfolio.portfolioName }}</option>
                        {% endfor %}
                </select>
            </p>
            <p>
                <input style="margin-left:100px; height:26px; cursor:pointer; background-color: #2D9AD3 !important; border: 1px solid #067EBD; color: #FFFFFF; text-shadow: 0 -1px 0 #067EBD;" type="submit"class="button2 tooltip" value="Switch">
            </p> 
        </form>
    </div>

在我的控制器中

if($request->getMethod() == 'POST'){
        $data = $request->request->all();
        //$portfolio_id = $data['portfolio_id'];
        var_dump($data);
        echo $data;
        exit();
    }

var_dump($data) 给了我这样的东西

array
 'portfolio' => string 'Umair Portfolio 1' (length=17)

Array

我怎样才能得到身份证?

有什么建议么?

提前致谢

4

1 回答 1

1

您必须将属性 id 更改为值

<option value={{ portfolio.id }}>{{ portfolio.portfolioName }}</option>
于 2012-06-04T22:47:31.313 回答