i made search form in my symfony2 application.but when i submit the form selected values not preserve on next render
i know i can achieve this through selected= "selected"
but how can i give that condition of GET variable because twig not supported php code in it
my code for sample like
<form action="{{ path('dcampaign') }}" method="get" class="doctor">
<select placeholder="Select Chronic Diseases" class="SlectBox" multiple="multiple" name="symptomlist[]" >
{% for symptoms in symptoms_array %}
<option value = {{symptoms.id}} >{{ symptoms.name}}</option>
{% endfor %}
</select>
<input type="submit" value="Create Campaign" class="btn btn-info" id="searchBtn" >
</form>
i tried app.request.query.get(); but doesn't help much...
You should keep this out of the Twig template, and do it in the controller. Personally, I would use the form library, so make a SearchType
with a symptoms
field. Then generate the form in Twig. I always implement search and filter fields in exactly that way.
If you can't or don't want to use the form library, then at least get the value from the request inside the controller action and pass it as a variable into Twig.