我有一段代码(smarrty html页面的一部分),它创建了一个位置的下拉列表,一旦选择了一个,第二个就会出现有位置。
问题是第二个字段不是必需的,我想要它是必需的,因为网站运行良好是非常重要的。
<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 :(得分:0)
如果您正在编辑HTML,是否已将REQUIRED添加到代码的末尾?
<input type="text" name="foo" value="bar" REQUIRED />
虽然这适用于现代浏览器(chrome + 20,Firefox 18+和Safari),但不能保证在旧浏览器中工作(猜测......是的IE)。所以我的下一个问题是你如何进行验证? JS还是PHP?