doujia1163 2012-04-04 05:28
浏览 87
已采纳

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

I have a form in a Code Igniter view in my jQuery Mobile application.

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

However, when I write this code into the controller method that the URL specified by action leads to:

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

"nay" is written to the page when I hit the submit button. How come Code Igniter cannot tell that I am submitting a post request?

  • 写回答

3条回答 默认 最新

  • dragonsun2005 2012-04-04 05:37
    关注

    If you want to determine if you have POST data or if request was a POST, use post() method from the input class

    $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"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集