問題描述
表單不通過 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 user3262234、cartalot)