如何将下拉选择值传递给smarty中的下一页

时间:2013-10-08 06:21:34

标签: html smarty

我正在smarty网站上搜索我正在使用的网站下拉框,文本框等。除了一个下拉框之外,一切正常。我没有得到我错的地方。           在主页上,我有下拉框。当你选择一些东西&点击提交按钮然后下一个表格打开&这里有相同的下拉框,所以它应该显示所选的值(我们在主页上选择)。但这确实没有发生。在这里,我发布了我尝试过的两种形式的代码。请帮帮我。           只有“cmbSidebarRegions”下拉框不起作用,除了一切正常。只有“cmbSidebarRegions”值未在表单提交时显示为选中。

1)这是一个主页

               {block name=header}
          <script type="text/javascript" src="{$smarty.const.PATH__JS}/ad.list.js"></script>
      {/block}
      <div id="QuickSearch" class="span-34 last prepend-1 prepend-top append-bottom">
          <div class="span-50 prepend-1 last">
                 <form method="post" action="?module=main&page=ad&action=list"> 
                 <div id="search_home" style="margin-left: 28px;">
                      {assign var="keyword" value=""}
                      {if isset($Keyword)}
                          {assign var="keyword" value=$Keyword}
                      {/if}
                      <input type="text" id="txtKeyword" name="txtKeyword" placeholder="Enter Keywords...." value="{$keyword}" style="width:532px;"/>
                      </div>
                      <div class="search_location" style="margin-top:8px;">
                      <label style="margin-left:6px; margin-right:6px;">in</label>
                      {assign var="Location" value=""}
                      {assign var="LocationID" value="-1"}
                      {assign var="LocationType" value="-1"}
                      {assign var="CityID" value="-1"}
                      {if isset($ObjRegion)}
                          {assign var="Location" value=$ObjRegion->strRegion}
                          {assign var="LocationID" value=$ObjRegion->intID}
                          {assign var="LocationType" value="region"}
                      {/if}
                      {if isset($ObjCity)}
                          {assign var="Location" value=$ObjCity->strCity}
                          {assign var="LocationID" value=$ObjCity->objRegion->intID}
                          {assign var="LocationType" value="city"}
                          {assign var="CityID" value=$ObjCity->intID}
                      {/if}
                      <select id="cmbSidebarRegions" name="cmbSidebarRegions" class="append-bottom" style="width:190px">
                          <option value="-1" selected="selected">All Ireland</option>
                          {foreach from=$Regions item=ObjRegion key=id name=index}
                              <optgroup label="{$ObjRegion->strRegion}">
                                  <option value="?module=main&page=ad&action=list&hdLocationType=region&hdLocationID={$ObjRegion->intID}">All Counties in {$ObjRegion->strRegion}</option>
                                  {foreach from=$ObjRegion->GetCities() item=ObjCity key=id name=index}
                                      {if isset($smarty.get.hdCityID) AND $smarty.get.hdCityID eq $ObjCity->intID}
                                          <option value="?module=main&page=ad&action=list&hdLocationType=city&hdCityID={$ObjCity->intID}" selected="selected">{$ObjCity->strCity}</option>
                                      {else}
                                          <option value="?module=main&page=ad&action=list&hdLocationType=city&hdCityID={$ObjCity->intID}">{$ObjCity->strCity}</option>
                                      {/if}
                                  {/foreach}
                              </optgroup>
                          {/foreach}
                      </select>
                      <input type="hidden" id="hdLocationType" name="hdLocationType" value="{$LocationType}"/>
                      <input type="hidden" id="hdCityID" name="hdCityID" value="{$CityID}"/>
                      <input type="hidden" id="hdLocationID" name="hdLocationID" value="{$LocationID}"/>
                      <!--<input type="text" id="txtLocation" name="txtLocation" placeholder="Location" value="{$Location}"/>-->
                      <label style="margin-left:6px; margin-right:6px;">in</label>
                      {assign var="keywordLocation" value=""}
                      {if isset($KeywordLocation)}
                          {assign var="keywordLocation" value=$KeywordLocation}
                      {/if}
                      <input type="text" id="txtKeywordLocation" name="txtKeywordLocation" placeholder="Location/Area" value="{$keywordLocation}"/>
                      <label style="margin-left:6px; margin-right:6px;">in</label>
                      <span class="selectbox">{include file="blocks/selectbox.tpl" ID="cmbSection" Name="cmbSection" Data=$Sections OptionText="All Sections" label="strSection" value="intID"}</span>
                      <button type="submit">Search</button>
                      </div>
              </form>
          </div>
      </div>

2)这是第2页

    {extends file="theme/master.tpl"}
    {block name=lang}{config_load file="lang.en.conf" section="HOME"}{/block}
    {block name=title}Ads Listing{/block}
    {block name=header}
        <script type="text/javascript" src="{$smarty.const.PATH__JS}/index.js"></script>
        <script type="text/javascript" src="{$smarty.const.PATH__JS}/ad.list.js"></script>
    {/block}
    {block name=SideBar}
        {include file="components/side.bar.tpl"}
    {/block}
    {block name=content}
         <div class="span-36 last">
            <div id="QuickSearch" class="span-34 last prepend-1 prepend-top">
                <div class="span-50 prepend-1 last">
                <div id="search_home" style="margin-left: 28px;">
                    {assign var="keyword" value=""}
                    {if isset($Keyword)}
                        {assign var="keyword" value=$Keyword}
                    {/if}
                    <input type="text" id="txtKeyword" name="txtKeyword" placeholder="Enter Keywords...." value="{$keyword}" style="width:509px;"/>
                    </div>
                    <div id="search_home" style="margin-left: 28px;">
                    {assign var="advertiser" value=""}
                    {if isset($Advertiser)}
                        {assign var="advertiser" value=$Advertiser}
                    {/if}
                    <input type="hidden" id="txtAdvertiser" name="txtAdvertiser" placeholder="Enter advertiser ID...." value="{$advertiser}" style="width:509px;"/>
                    </div>
                <div class="search_location" style="margin-top:8px;">
                    <label style="margin-left:6px; margin-right:6px;">in</label>
                    <select id="cmbSidebarRegions" name="cmbSidebarRegions" class="append-bottom" style="width:161px">
                        <option value="-1" selected="selected">All Ireland</option>
                        {foreach from=$Regions item=ObjRegion key=id name=index}
                            <optgroup label="{$ObjRegion->strRegion}">
                                <option value="?module=main&page=ad&action=list&hdLocationType=region&hdLocationID={$ObjRegion->intID}">All Counties in {$ObjRegion->strRegion}</option>
                                {foreach from=$ObjRegion->GetCities() item=ObjCity key=id name=index}
                                    {if isset($smarty.get.hdCityID) AND $smarty.get.hdCityID eq $ObjCity->intID}
                                        <option value="?module=main&page=ad&action=list&hdLocationType=city&hdCityID={$ObjCity->intID}" selected="selected">{$ObjCity->strCity}</option>
                                    {else}
                                        <option value="?module=main&page=ad&action=list&hdLocationType=city&hdCityID={$ObjCity->intID}">{$ObjCity->strCity}</option>
                                    {/if}
                                {/foreach}
                            </optgroup>
                        {/foreach}
                    </select>

                    <input type="hidden" id="hdLocationType" name="hdLocationType" value="{$LocationType}"/>
                    <input type="hidden" id="hdCityID" name="hdCityID" value="{$CityID}"/>
                    <input type="hidden" id="hdLocationID" name="hdLocationID" value="{$LocationID}"/>
                    <label style="margin-left:6px; margin-right:6px;">in</label>
                    {assign var="keywordLocation" value=""}
                    {if isset($KeywordLocation)}
                        {assign var="keywordLocation" value=$KeywordLocation}
                    {/if}
                    <input type="text" id="txtKeywordLocation" name="txtKeywordLocation" placeholder="Location/Area" value="{$keywordLocation}"/>
                    <label style="margin-left:6px; margin-right:6px;">in</label>
                    {assign var="SectionID" value=-1}
                    {if isset($Section)}
                        {assign var="SectionID" value="{$Section->intID}"}
                        {assign var="valsect" value="{$Section->strSection}"}
                    {/if}
                    {assign var="SubSectionID" value=-1}
                    {if isset($SubSection)}
                        {assign var="SectionID" value="{$SubSection->objSection->intID}"}
                        {assign var="SubSectionID" value="{$SubSection->intID}"}
                        {assign var="valsubsect" value="{$SubSection->strSubSection}"}
                    {/if}
                    <input type="hidden" id="hdSectionID" name="hdSectionID" value="{$SectionID}"/>
                    <input type="hidden" id="hdSubSectionID" name="hdSubSectionID" value="{$SubSectionID}"/>
                    <span class="selectbox">
                        <select id="cmbSectionGroup" name="cmbSectionGroup"  style="width:150px">
                            <option value="-1">All Sections</option>
                            {foreach from=$arrSections item=Section}
                                <optgroup label="{$Section->strSection}">
                                    <option value="section_{$Section->intID}">All Subsections in {$Section->strSection}</option>
                                    {foreach from=$Section->arrSubSections item=SubSection}
                                        <option value="{$SubSection->intID}">{$SubSection->strSubSection}</option>   
                                    {/foreach}   
                                </optgroup>
                            {/foreach}
                        </select>
                    </span>
                    </div>
                </div>
                <div class="span-32 prepend-1 prepend-top">
                    <hr/>
                </div>
                <div class="span-32 prepend-1 last prepend-top-xxx">
                    <a id="btnSearchOptions" class="ss_sprite ss_bullet_toggle_plus" onclick="ShowSearchOptions()">Show More Search Options</a>
                    <div id="pnlAdvancedSearch" class="hide span-32 prepend-1 last prepend-top-xxx">
                    </div>
                </div>
                <div class="span-32 align-right prepend-top-x">
                    <button onclick="NextPageAds(1)" style="width:90px;cursor:pointer">Search</button>
                    <button onclick="Reset()" style="width:90px;cursor:pointer">Reset</button>
                </div>
            </div>
        </div>

        <div id="midlink">
        <div class="left">
        </div>
        <div class="right">
        <input type="button" value="Send me web feeds for this category" onclick="window.location = '?module=main&page=webfeeds&action=Subscribe'"/>
        </div>
        </div>
        <div class="span-36 last">
            <div id="pnlAds" class="span-34 last prepend-1 append-1 prepend-top append-bottom">
            </div>
        </div>
    {/block}

1 个答案:

答案 0 :(得分:2)

您必须从第二种形式的第一个选项中删除“selected”属性:

<option value="-1" selected="selected">All Ireland</option>

另请注意,您正在查看hdCityID值以设置当前所选项目,这两个表单中都是隐藏字段且永远不会更改(除非您使用javascript执行此操作):

{if isset($smarty.get.hdCityID) AND $smarty.get.hdCityID eq $ObjCity->intID}

...

<input type="hidden" id="hdCityID" name="hdCityID" value="{$CityID}"/>

这意味着你在cmbSidebarRegions中选择了什么并不重要。更好地修改代码逻辑。