请耐心等待,如果这篇文章太长,我道歉......
我正在尝试在Magento中构建自定义高级搜索表单。基本上,我有一堆选择框,所选值与我的Magento产品属性值相对应并附加到URL,所以如果你有一个这样的选择框:
<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>
你选择“小”,URL会导致:
http://mymagento.com/catalogsearch/advancedsearch/result/?diameterange=15
您可以看到我正在回显这些值,以便在加载结果页面时,用户会在新搜索结果上方看到相同的搜索表单及其选择的选项。除了特别是一个属性 - price[from]
。
以下是我的price[from]
选择框的代码:
<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>
这个框及其选中的值在URL附加的情况下正常工作,它会为您带来正确的结果,但我无法让这个选择框记住它的值,就像我可以使用其他属性一样。因此,如果用户在此框中选择了某个值,则不会在搜索结果页上的搜索表单中预先选择他的选择。
我确信这与选择框的名称和ID中的[]括号有关。如何回应此特定框的选定选项?
谢谢
答案 0 :(得分:1)
应该是
$_SESSION['post']['price']['from']
代替。您可以执行var_dump($_SESSION['post'])
验证。
答案 1 :(得分:1)
不确定如何将$ _POST翻译成会话,但也许您想尝试将$_SESSION['post']['price[from]']
更改为$_SESSION['post']['price']['from']