2011-04-14 206 views
0

請有以下鏈接訪問:Demo link for problem笨:提交的表單不顯示值

您可以查看錶格沒有顯示提交的值,而不能上傳文件。

以下是表單代碼:

<form id="frm" name="frm" method="post" enctype="multipart/form-data"> 
      <fieldset class="fieldset2"> 

       <legend class="legend2">Add Bid Type</legend> 

       <div class="form_fields"> 

       <p> 
       <label for="subject" class="label2">Bid Type:</label> 
       <input type="input" id="type" name="type" class="textfield2" /> 
       </p> 

       <p> 
       <label for="subject" class="label2">Bid Type Code:</label> 
       <input type="input" id="code" name="code" class="textfield2" /> 
       </p> 


       <p> 
       <label for="description" class="label2">Bid Type Description:</label> 
       <textarea id="description" name="description" class="textarea2"></textarea> 
       </p> 




       <p> 
       <label for="userfile" class="label2">Icon:</label> 
       <input type="file" id="userfile" name="userfile" class="input_file" /> 
       </p> 


       </div> 

      </fieldset> 

      <fieldset class="none"> 
      <p> 
       <input type="submit" id="btnsubmit" name="btnsubmit" class="btn" value="Add" /> 
    <input type="reset" id="btnreset" name="btnreset" class="btn" value="Reset" /> 
      </p> 
      </fieldset> 
     </form>` 

而且下面是控制器代碼:

function create() { 

     $data = ''; 


     echo '<pre>'; 
     echo 'below is Post Fields Data:<br>'; 
     print_r($this->input->post()); 
     echo '<br>Post Fields Data Ends: ';  

    echo '</pre>'; 



     $this->form_validation->set_rules('type', 'Bid Type', 'trim|required|xss_clean'); 
     $this->form_validation->set_rules('code', 'Bid Type Code', 'trim|xss_clean'); 

     $this->form_validation->set_rules('description', 'Bid Type description', 'trim|xss_clean'); 

     $data['errors'] = array(); 

     if ($this->form_validation->run()) { 
       $data = array(
        'code'   => $this->form_validation->set_value('code'), 
        'type'   => $this->form_validation->set_value('type'), 
        'description' => $this->form_validation->set_value('description'), 

       ); 

       if (!is_null($this->bid_types->create_bid_type($data))){ 
         $data['errors']['success'] = 'Record Successfully Added!'; 


       } else { 

        $errors = $this->bid_types->get_error_message(); 
        foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v); 

       }  

     $config['upload_path'] = base_url().'resource/images/uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png'; 
     //$config['max_size'] = '100'; 
     //$config['max_width'] = '1024'; 
     //$config['max_height'] = '768'; 

    $this->load->library('upload', $config); 

    if (! $this->upload->do_upload()) 
    { 
     $data['errors']['upload'] = 'Not Uploaded'; 
     //$data['errors']['upload'] = $this->upload->display_errors(); 
     //$error = array('error' => $this->upload->display_errors()); 

     //$this->load->view('upload_form', $error); 
    } 
    else 
    { 
     $data['errors']['upload'] = 'Yes Uploaded'; 
     //$data['errors']['upload'] = $this->upload->data(); 
     //$data = array('upload_data' => $this->upload->data()); 

     //$this->load->view('upload_success', $data); 
    } 

    echo '<pre>';   
     print_r($this->upload->data()); 

    echo '</pre>'; 

     } /* END OF FORM VALIDATRION RUN */ 

     if(!$this->input->is_ajax_request() && !$this->input->get_post('is_ajax')) 
     { 
      $this->load->view('bend/bid_type/create', $data); 

     }        


} /* END OF FUNCTION CREATE */ 

有人可以指導我什麼,在哪裏蔭做錯了,如何可以rectrified。

回答

1

文件數據出現在$ _FILE而不是$ _POST中。

我覺得這條線是你的問題:

$config['upload_path'] = base_url().'resource/images/uploads/'; 

$config['upload_path']應指向文件系統路徑,而不是URL。 嘗試更多的東西一樣:

$config['upload_path'] = realpath(APPPATH . '../resource/images/uploads/'); 

將從您的application文件夾啓動,上一級文件夾,然後進入resource/images/uploads 改變其相應的如果別的地方。

p.s.同時檢查你的寫入權限。

+0

真正找到解決方案 – Simpanoz 2011-04-14 09:34:51

0

$this->output->enable_profiler(TRUE)create()函數的第一行,它會告訴你非常有用的信息$_POST global調試代碼就像

+0

謝謝你的提示。你能指導我爲什麼沒有上傳文件,它不顯示在PROFILER – Simpanoz 2011-04-14 09:08:10

0

Charles顯示,從形式的請求提交確實包含POST數據。

Charles Output

是否其他任何可能擦拭POST數據的創建()函數之前發生的呢?

+0

PROFILER也顯示POST數據。但是,文件上傳字段有什麼問題,它根本不起作用。 – Simpanoz 2011-04-14 09:13:43

0

我會添加一個action屬性的形式使用echo form_open('/phpdemo/b1/admin/bid_type/create')the user manual所述。

0

不能使用

$this->form_validation->set_rules('code', 'Bid Type Code', 'trim|xss_clean'); 
在多

,所以你必須創建自己的功能驗證和使用callbacks