-6ren">
gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 22:57:42 25 4
gpt4 key购买 nike

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

<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>

但是,当我将这段代码写入到 action 指定的 URL 导致的 Controller 方法中时:

echo ($_SERVER['REQUEST_METHOD'] == 'POST') ? "yay" : "nay";

当我点击提交按钮时,“nay”被写入页面。为什么 Code Igniter 无法判断我正在提交帖子请求?

最佳答案

如果您想确定您是否有 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"

关于php - 为什么 Code Igniter 无法检测到我的表单是通过 POST 提交的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10005393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com