2013-10-20 54 views
0

我有一段代碼(一個smarrty html頁面的一部分),它創建一個下拉列表的位置,一旦選擇了一個,第二個出現有sublocations。要求Smarty字段

問題是,第二個字段不是必需的,我想使它成爲必需的,因爲它對網站來說足夠好用了。

       <div class="control-group" style="margin-top:50px"> 
            <label class="control-label"></label> 
            <div class="controls"> 
             <h5 style="font-weight:700">Enter Your Property City or Municipality</h5> 
            </div> 
           </div> 
           {if $field_enable_listing_location == "yes"} 
           <div class="control-group {$warning_listing_location_1}"> 
            <label class="control-label">{$field_name_listing_location} <span class="required">*</span></label> 
            <div class="controls"> 

             <div id="listing_location_1" style="current:block; padding-top:0px"> 
              <select name="listing_location_1" id="box_listing_location_1" class="span6 m-wrap" onchange="find_child_location(this.value, {$setup_import_loc_level}, 'system_setup_location_ajax_sum.php?parent='+this.value, 'system_setup_location_ajax_list.php?box_level=2&box_width=400&box_class=span6 m-wrap&box_name=listing_location&parent='+this.value, 1, 'listing_location_2', 'listing_location_notification'); change_color('box_listing_location_1', '#FFFFFF', 'black', 'lbl_listing_location_1', 'black')"> 
              <option value="">Choose your property region</option> 
              {section name=var loop=$location_lv1_id} 
              <option value="{$location_lv1_id[var]}" {if $location_lv1_id[var] == $clisting_location_1} selected {/if} >{$location_lv1_name[var]}</option> 
              {/section} 
              </select> 
              <input type="hidden" name="required_listing_location_1" value="text" /> 
             </div> 

             {section name=var loop=$location_current} 

              <div id="listing_location_{$location_current[var]}" style="current:none; padding-top:{$location_padding[var]}"> 
              {if $location_show[var] == "yes"} 
               <select name="listing_location_{$location_current[var]}" class="span6 m-wrap" onchange="find_child_location(this.value, {$setup_import_loc_level}, 'system_setup_location_ajax_sum.php?parent='+this.value, 'system_setup_location_ajax_list.php?box_level={$location_next[var]}&box_width=400&box_class=span6 m-wrap&box_name=listing_location&parent='+this.value, {$location_current[var]}, 'listing_location_{$location_next[var]}', 'listing_location_notification');"> 
               {section name=sub loop=$location_list_id[var]} 
               <option value="{$location_list_id[var][sub]}" {if $location_list_id[var][sub] == $location_value[var]} selected {/if}>{$location_list_name[var][sub]}</option> 
               {/section} 
               </select> 
              {/if} 
              </div> 

             {/section} 

地方後,有:

     listing_location_1:       {ldelim} required: true {rdelim}, 

和別的地方:

     listing_location_1:       {ldelim} required: "Please fill this field." {rdelim}, 

有沒有一種方法,我可以使第二場強制性?

回答

0

如果您正在編輯HTML,是否在標籤的末尾添加了REQUIRED?

<input type="text" name="foo" value="bar" REQUIRED /> 

雖然這部作品在現代瀏覽器(鉻+20,18歲以上的Firefox和Safari),它不能保證在舊的瀏覽器工作(猜...是IE)。所以我的下一個問題是你如何做你的驗證? JS或PHP?

+0

我剛加入這個: listing_location_2:{} ldelim要求:真{} rdelim, 和它的工作是有原因的。 我添加了你建議的代碼,但沒有在smarty上工作。 – NickHoot

+0

嗯,我會認爲HTML是HTML,但也許它會在瀏覽器中渲染出來時將其過濾掉。很高興你知道了 – Sparatan117