为什么可以';t代码点火器检测到我的表单正在通过POST提交


Why can't Code Igniter detect that my form is being submitted via POST?

我在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";

当我点击提交按钮时,页面上会写上"不"。为什么Code Igniter不能告诉我正在提交帖子请求?

如果您想确定您是否有POST数据或请求是否是POST,请使用输入类中的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"

它可能是register_globals的原因。使用

if($_POST) 

OR CI输入类

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

我想知道你的表单是否像你预期的那样返回了一个post请求,但之后有东西立即重定向,你认为这是一个GET?尝试将临时exit()立即放入表单处理操作中;我怀疑这会变成POST。

相关文章: