Codeigniter表单POST在控制器从视图中为空 [英] codeigniter form POST Empty in Controller from View

查看:55
本文介绍了Codeigniter表单POST在控制器从视图中为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Codeigniter合作.我创建了一个HTML表单,该表单将数据发布到Controller.

I'm working with Codeigniter. I have created an HTML form which post data to the Controller.

此表单运行正常,但突然停止发布数据.

This Form was working perfectly but it suddenly stopped posting data.

HTML:

<form name="frm_search" id="frm_search" method="post" action="http://ip/free/index.php/taskdetails/tabOne/1/ShibNo/asc/">
<input  id="order1" name="order1" value="26" type="text" >
<input  id="item1" name="item1" value="" type="text" >
</form>

  1. 我尝试在浏览器中检查数据发布,它显示了我在输入框中输入的数据.

  1. 在我的index.php中,放置了以下代码以查看其是否已发布:

echo "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "";
$data = file_get_contents('php://input');
echo "DATA: <pre>";
var_dump($data);
var_dump($_POST);
echo "</pre>"; 
exit; 

结果:

CONTENT_TYPE:应用程序/x-www-form-urlencoded

CONTENT_TYPE: application/x-www-form-urlencoded

字符串'order1 = 26& item1 ='

string 'order1=26&item1='

数组(大小= 23)
'order1'=>字符串'26'(长度= 2)
'item1'=>字符串''(长度= 0)

array (size=23)
'order1' => string '26' (length=2)
'item1' => string '' (length=0)

但是当我在控制器中打印$ _POST时,我得到以下信息:

But when I print $_POST in controller I get the following:

Array
(
    [order1] => 
    [item1] =>
)

  1. 我的.htaccess代码如下:

  1. My .htaccess code as follows:

RewriteEngine on

RewriteCond $1 !^(index\\.php|resources|robots\\.txt)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

有人可以告诉我这是什么问题吗?我无法找出为什么当数据传递到控制器时它变为空.该应用程序已成功运行了一年多,但突然出现了这个问题.

Can someone tell me what's the issue? I'm not able to find out why is it when the data passes to controller it becomes null. The application was running successfully for more than a year but I got this issue suddenly.

先谢谢您.请让我知道是否需要更多帮助.

Thank you in advance. Kindly let me know if you need any more to help me.

注意:我发现加载页面后,如果将输入的名称编辑为其他名称,则数据将成功发布.

Note: I figured out that once the page is loaded, If I edit the name of the input to some other name then the data is post successfully.

即:,而不是 order1 ,如果我将使用Chrome中的inspect元素将编辑名称更改为"新订单",则如果我提交,数据将有价值地提交给控制器.不知道为什么吗

i.e: instead of order1, If I change the name my editing using inspect element in Chrome to "neworder" Then if I submit, the data submits with value to controller. Don't know why?

更新:我发现了一些奇怪的地方.在浏览器的set-cookie中.就像整页的垃圾一样.

Update: I found some this strange. In the set-cookie of the browser. It's like a full page of junk.

每次调用该页面时,我都会启动一个新会话,但不会终止现有会话.那是问题吗?

Each time when the page is called i start a new session but i wont kill the existing session. Is that a problem?

即使我破坏了旧的会话并开始新的会话,我也会在浏览器中获得eh set-cookies.它对我来说是一个..但就我而言,我在浏览器中获得了6个以上的cookie.

Even If i destroy the old session and start new one I get eh set-cookies in browser. It has to me one.. but in my case I get more than 6 set cookies in the browser.

推荐答案

根据此CI github发布问题

It could be a .htaccess issue with RewriteRule, according to this CI github post issue https://github.com/bcit-ci/CodeIgniter/issues/242:

如果使用Apache服务器,则应启用mod rewrite,否则重定向将是正确的,但$ _POST为空.

if Apache server is used then mod rewrite should be enabled, otherwise redirection will be proper but with empty $_POST.

&

如果您的网址上没有斜杠,则服务器将发送一个301重定向,它将干扰POST数据.

if you don't have a trailing slash on your URL the server will send a 301 redirect which will interfere with POST data.

您的问题可能出在

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

尝试更改为:

RewriteRule ^(.*)$ index.php/$1 [PT,L]

(来自:无法在codeigniter )或尝试设置:

(from: not able get post form submit values in codeigniter) or try to set:

sudo a2enmod rewrite

希望有帮助!

这篇关于Codeigniter表单POST在控制器从视图中为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆