testmyname 发表于 2012-9-7 10:17:57

set_select 不起作用

视图代码
<select id="year" name="year">
      <option value="" <?php echo set_select('year', '', TRUE); ?>>请选择</option>
      <?php for($i=1994;$i>=1950;$i--){?>
      <option value="<?php echo $i;?>" <?php echo set_select('year', $i); ?>><?php echo $i;?></option>
      <?php }?>
</select>
控制器代码
function xxx(){
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('year', '年份', 'callback_date_required');
........
}

function date_required($str)
{
if ($str == '')
{
   $this->form_validation->set_message('date_required', '日期填写不完整');
   return FALSE;
}   
}


同样的还有月份 日期为何提交不成功后select的值仍然被重置?哪里有错误?

testmyname 发表于 2012-9-7 10:41:23

是因为填充时$i 还未赋值所以无法选中? 那这种动态赋值的情况该如何解决?

testmyname 发表于 2012-9-7 10:51:54

已解决:看来是那个原因,所以只好用$_post判断

testmyname 发表于 2012-9-11 10:16:06

还是没有解决 上面办法不行 只能$this->form_validation->set_rules('year');这样就可以 不能再有其他参数
页: [1]
查看完整版本: set_select 不起作用