Reputation: 1699
I have a form with only one select tag. I want to get the id of the selected option tag in my controller when a user submit the form. My form is
<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>
In my controller
if($request->getMethod() == 'POST'){
$data = $request->request->all();
//$portfolio_id = $data['portfolio_id'];
var_dump($data);
echo $data;
exit();
}
the var_dump($data) gives me something like this
array
'portfolio' => string 'Umair Portfolio 1' (length=17)
Array
How can I get the id ?
Any suggestions?
Thanks in advance
Upvotes: 0
Views: 2512
Reputation: 4092
you must change attribute id to the value
<option value={{ portfolio.id }}>{{ portfolio.portfolioName }}</option>
Upvotes: 1