使用Codeigniter进行表单下拉验证

时间:2014-03-21 08:23:52

标签: php html codeigniter

我的要求是在提交表单时向表单提交表单下拉列表,同时提交表单必须检查是否选择了燃料类型 我从数据库获得燃料类型 我的代码在视图中

public function create_vehicle_ad()
{
       $this->form_validation->set_rules('js_Fuel_Type', 'Fuel Type', 'required|is_natural');
      if($this->form_validation->run()== FALSE)
        {
    $data['fuel_type'] = $this->create_ad->getFuelType();
       $this->load->view('create_vehicle_ad',$data);
          }
}

我的模型代码

public function getFuelType()
{
    $this->db->select('Fuel');
    $this->db->from('ref_vehicle_fuel_type'); 
    $query = $this->db->get();
    $data=array();
    $data[0]='SELECT';
     foreach($query->result_array() as $row){
       $data[$row['Fuel']]=$row['Fuel'];
    }
    return $data;
}

我在视野中的代码

<div class="form-group">
    <label class="control-label col-md-3 mail-text" for="select"><span class="star">*</span>Fuel Type :</label>
    <div class="col-md-3">
                <?php 
                         $js = 'id = "js_Fuel_Type" class="form-control"';  
                         echo form_dropdown('js_Fuel_Type',$fuel_type,set_value(js_Fuel_Type,$js_Fuel_Type,TRUE),$js);
                         echo "<span class='star'>"; echo form_error("js_Fuel_Type");echo "</span>";
                ?> 
    </div> 

    </div>

Plz提前帮助我

0 个答案:

没有答案