2013-10-08 29 views
-1

我正在smarty網站上尋找我正在使用的網站下拉框,文本框等。除了一個下拉框外,所有工作都正常。我不明白我出錯的地方。 在主頁上我有下拉框。當你選擇&命中提交按鈕,然後下一個窗體打開&這裏有相同的下拉框,所以它應該顯示選定的值(我們在主頁上選擇)。但是,這並沒有發生。在這裏,我發佈了兩種形式的經過驗證的代碼。請幫助我。 只有「cmbSidebarRegions」下拉框不起作用,除非一切正常。只有「cmbSidebarRegions」值在表單提交時沒有顯示爲選中狀態。如何將下拉選定值傳遞到smarty的下一頁

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

你必須從第二形態的第一個選項中刪除了「選擇」屬性:

<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。更好地修改你的代碼邏輯。

+0

嘿Borgtex謝謝,我試過了。但它不工作。 – vickram

+0

請閱讀修訂後的答案 – Borgtex

+0

謝謝Borgtex。我已經在代碼中做了足夠的改變,現在它的工作正常。謝謝你的幫助。 – vickram

相關問題