2017-12-26 5 views
0

次のモデルビューコントローラを試しましたが、複数の行を一度に送信する必要があります。codeigniter同じ名前の複数の行を送信する方法

これは私のコントローラである:

function add_item(){ 
$this->form_validation->set_rules('item_name', 'Item Name', 'trim|required'); 

     if ($this->form_validation->run() == FALSE) 
     { 
      $this->load->model('mdl_item'); 
      $data['main_content'] = 'backend/items/add_item'; 
      $data['title'] = 'Create item'; 
      $this->load->view('includes/template', $data); 
     } 
     else 
     { 
      $this->load->model('mdl_item'); 
      $data = $this->input->post(); 
      $this->mdl_item->create_item($data); 
       $this->session->set_flashdata('message', 'Items successfully created'); 
      redirect('admin/items', 'refresh'); 
     } 


    } 

これは私のモデルである:

function create_item($data) 
    { 

      $data['expiry_date'] = date('Y-m-d', strtotime(element('expiry_date', $data))); 
      $crop_data = elements(array(
      'item_name', 

      ), $data); 
      $add_item = $this->db->insert_string('items', $crop_data); 
      $this->db->query($add_item); 


    } 

これは私のビューです:

<?php echo form_open('admin/items/add_item', 'id="item_form_validate"'); ?> 
    <div class="col-sm-12 col-md-12 jumbotron"> 

<input type="text" class="form-control" name="item_name[]" value="<?php echo set_value('item_name'); ?>"> 
<input type="text" class="form-control" name="item_name[]" value="<?php echo set_value('item_name'); ?>"> 
<input type="text" class="form-control" name="item_name[]" value="<?php echo set_value('item_name'); ?>"> 


<button type="submit" class="btn btn-success" value="submit"><span class="icon-checkmark"></span> <?php echo lang('Submit'); ?></button> 
</form> 
+0

通過した後、値をトリミングするコントローラの電子コードset_rules('item_name',? –

答えて

1

チャン

... 
     function add_item(){ 
      $this->form_validation->set_rules('item_name', 'Item Name', 'trim|required'); 

このset_rules('item_name[]'

... 
     function add_item(){ 
      $this->form_validation->set_rules('item_name[]', 'Item Name', 'required'); 

、あなたはそれがこのの電流出力するものである

関連する問題