简体   繁体   English

为什么我不能保留这个选择框的值? ([]括号中的选择框名称和ID)

[英]Why can't I retain this selection box's value? ([ ] brackets in select box name and ID)

Please bear with me, my apologies if this post is too long... 请耐心等待,如果这篇文章太长,我道歉...

I'm attempting to build a custom advanced search form within Magento. 我正在尝试在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: 基本上,我有一堆选择框,所选值与我的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>

And you chose "Small", the URL would result in: 你选择“小”,URL会导致:

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] . 除了特别是一个属性 - price[from]之外,这一切都很好用。

Here is the code for my price[from] selection box: 这是我的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>

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. 这个框及其选中的值在URL附加的情况下正常工作,它会为您带来正确的结果,但我无法让这个选择框记住它的值,就像我可以使用其他属性一样。 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. 我确信这与选择框的名称和ID中的[]括号有关。 How can I echo the selected choice for this particular box? 如何回应此特定框的选定选项?

Thank you 谢谢

It should be probably be 应该可能是

$_SESSION['post']['price']['from']

instead. 代替。 You can verify by doing a var_dump($_SESSION['post']) . 您可以通过执行var_dump($_SESSION['post'])

不确定你如何将$ _POST翻译成会话,但也许你想尝试将$_SESSION['post']['price[from]']改为$_SESSION['post']['price']['from']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM