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

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探