Please bear with me, my apologies if this post is too long…
I’m attempting to build a custom advanced search form within Magento. Basically, I have a bunch of select boxes and the selected values correspond with my Magento product attribute values and append to the URL, so if you had a selection box like this:
<select name="diameterange" id="diameterange">
<option value=''<?php echo $_SESSION['post']['diameterange']=='all'?'selected="selected"':''; ?>>all</option>
<option value='15'<?php echo $_SESSION['post']['diameterange']=='15'?'selected="selected"':''; ?>>Small</option>
<option value='14'<?php echo $_SESSION['post']['diameterange']=='14'?'selected="selected"':''; ?>>Medium</option>
<option value='13'<?php echo $_SESSION['post']['diameterange']=='13'?'selected="selected"':''; ?>>Large</option>
And you chose “Small”, the URL would result in:
http://mymagento.com/catalogsearch/advancedsearch/result/?diameterange=15
You can see I’m echoing the values so that when the results page is loaded, the user sees the same search form with their selections pre-selected, above their new search results. This all works fine and dandy except for one attribute in particular – price[from].
Here is the code for my price[from] selection box:
<select name="price[from]" id="price[from]">
<option value=''<?php echo $_SESSION['post']['price[from]']==''?'selected="selected"':''; ?>>from (all)</option>
<option value='100'<?php echo $_SESSION['post']['price[from]']=='100'?'selected="selected"':''; ?>>from $100</option>
<option value='200'<?php echo $_SESSION['post']['price[from]']=='200'?'selected="selected"':''; ?>>from $200</option>
<option value='300'<?php echo $_SESSION['post']['price[from]']=='300'?'selected="selected"':''; ?>>from $300</option>
<option value='400'<?php echo $_SESSION['post']['price[from]']=='400'?'selected="selected"':''; ?>>from $400</option>
<option value='500'<?php echo $_SESSION['post']['price[from]']=='500'?'selected="selected"':''; ?>>from $500</option>
<option value='600'<?php echo $_SESSION['post']['price[from]']=='600'?'selected="selected"':''; ?>>from $600</option>
<option value='700'<?php echo $_SESSION['post']['price[from]']=='700'?'selected="selected"':''; ?>>from $700+</option>
</select>
This box and its selected value works correctly as far as the URL appending goes, and it will bring you the correct results, but I cannot get this selection box to remember its value like I can with the other attributes. So if a user has chosen a value in this box, his choice isn’t pre-selected on the search form on the search results page.
I’m convinced this has something to do with the [ ] brackets in the select box’s name and ID. How can I echo the selected choice for this particular box?
Thank you
It should be probably be
instead. You can verify by doing a
var_dump($_SESSION['post']).