为什么Code Igniter无法检测到我的表单是通过POST提交的?

时间:2012-04-04 05:28:47

标签: php codeigniter

我的jQuery Mobile应用程序中的Code Igniter视图中有一个表单。

<form action="<?= BASE_PAGE_URL ?>settings" method="post" id="settingsForm">
    <div data-role="fieldcontain">
        <label for="firstName">First Name</label>
        <input type="text" name="firstName" id="firstName" value="" placeholder="First Name" />
    </div>
    <div data-role="fieldcontain">
        <label for="lastName">Last Name</label>
        <input type="text" name="lastName" id="lastName" value="" placeholder="Last Name" />
    </div>
    <input type="hidden" name="purpose" value="register" />
    <input type="submit" name="submit" value="Register" />
</form>

但是,当我将此代码写入控制器方法时,操作指定的URL会导致:

echo ($_SERVER['REQUEST_METHOD'] == 'POST') ? "yay" : "nay";
当我点击提交按钮时,

“nay”被写入页面。为什么Code Igniter无法告诉我我正在提交帖子请求?

3 个答案:

答案 0 :(得分:2)

如果您想确定是否有POST数据或请求是POST,请使用input class

中的post()方法
$this->input->post(index);

//returns FALSE if no POST data
//returns the POST array if there is data (hence, a POST)
//returns a specific data from the array if you provide "index"

答案 1 :(得分:2)

可能是register_globals的原因。使用

if($_POST) 

OR CI输入类

$this->input->post('var');

答案 2 :(得分:1)

我想知道你的表单是否按照你的预期返回了一个帖子请求,但之后会立即重定向,你看到它是一个GET?尝试将临时exit()立即放入表单处理操作中;我怀疑它会以POST形式出现。