2012-03-28 54 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