表單不通過 Post 發送數據 (Form not sending data through Post)


問題描述

表單不通過 Post 發送數據 (Form not sending data through Post)

作為一個大項目的一部分,我正在使用 PHP 和 CodeIgniter 實現一個簡單的時事通訊表單。

我的 HTML 代碼如下。

<form method="POST" action='http://sit.com/index.php/Users/subscribenews'>
<div class="input‑group">
<input type="email" id="pkemailid" name="pkemailid">
<span class="input‑group‑btn">
<button class="btn btn‑lg btn‑primary" type="submit"> Go
</button>
</span>
</div><!‑‑ /input‑group ‑‑>
</form>

在我的控制器中,我正在處理值為

$emailid = $this‑>input‑>post('pkemailid');

當我對 $_POST 變量執行 var_dump 時,我得到以下結果

array(0) { }

最大的問題是我能夠在我的 WAMP 服務器上正確運行它在本地主機上,但它在託管服務器上不起作用。

有趣的是,如果我將 POST 更改為 GET,它就會開始工作。


參考解法

方法 1:

this line

<input type="email" id="pkemailid" name="pkemailid">

try changing it to

<input type="text" id="pkemailid" name="pkemailid">

type="email" is html 5 only and i don't know for certain ‑‑ but codeigniter might not support html 5 form values.

===== edit

so my suggestion when you are at the hair pulling questioning reality stage of trying to find a bug ‑ get a fresh new copy of codeigniter, install on your server, make sure you get the welcome page. now make the simplest form possible and echo something out from the controller method to make sure that you are submitting the form to the correct method. Next add a hidden form field with a value, and echo out that value from your method.

If all that works, then its not your server you have bug in your original code. And if it doesn't work then you have an issue with the server.

(by user3262234cartalot)

參考文件

  1. Form not sending data through Post (CC BY‑SA 2.5/3.0/4.0)

#post #input #codeigniter #PHP






相關問題

將 xml 從經典 asp 發佈到 asp.net (Posting xml from classic asp to asp.net)

POST 和 PUT HTTP 請求有什麼區別? (What's the difference between a POST and a PUT HTTP REQUEST?)

使用 formdata 發布數組 (Posting array using formdata)

儘管表單,Django POST dict 為空 (Django POST dict empty despite form)

表單提交為空 (Form submission empty)

ajax post 只看到第一個參數 (ajax post only sees first param)

使用 PHP 變量搜索 SQL 數據庫 (Use PHP variable to search through SQL database)

表單不通過 Post 發送數據 (Form not sending data through Post)

在 PHP 中使用 cURL 的 RAW POST (RAW POST using cURL in PHP)

使用 php 和 curl 更新 mediawiki (using php and curl to update mediawiki)

在 python 中開發時,如何在 post 請求中使用“format=json&data=”? (How do I use "format=json&data=" in post requests when developing in python?)

Nodejs GET 和 POST 在實時服務器中混合,但在 localhost 中工作 (Nodejs GET and POST mixed up in live server but working in localhost)







留言討論