2012-03-28 30 views
4
到控制器

我的觀點:如何發佈表單數據使用GET方法笨

<form action="<?=base_url()?>index.php/frontend/main_con/temp"> 
    <input type="text" name="temp"> 
    <input type="submit"/> 
</form> 

控制器:

function temp(){ 
    echo $_GET['temp']; 
} 

我不能能達到這個功能,我得到一個錯誤

遇到錯誤 您提交的URI不允許使用字符。

那麼,如何使用GET方法在控制器中傳遞表單數據? thanx提前。

+0

我只是好奇你爲什麼需要使用通過POST的GET來檢索值? – Catfish 2012-03-28 16:04:51

回答

2
parse_str($_SERVER['QUERY_STRING'],$_GET); 

後我加入以下行應用程序只爲我工作/配置/ config.php文件:

$config['uri_protocol'] = "PATH_INFO"; 
1

要解決此錯誤,請轉至this line。我個人認爲,這是設計上的錯誤,因爲來自URI的黑名單符號會比白名單更好。

至於GET變量..你將不得不使用<form method="get" action="/what/ever/">

7

查看:

<form action="<?=site_url('controller_name/function_name);?>" method="get"> 
    <input type="text" name="temp"> 
    <input type="submit"/> 
</form> 

控制器

class controller_name extends CI_Controller{ 

    function function_name(){ 
     echo $this->input->get('temp'); 
    } 

} 
1
+0

爲什麼?根據我的知識,每個表單都必須通過php中的「post」和「get」方法發佈。 – 2012-03-29 06:31:53

+0

我不能理解「得到」那麼好。當我在CI和表單數據中工作時,我總是用CI方法'$ this-> input-> post('temp');'訪問它。 – Catfish 2012-03-29 13:20:12