我的Codeigniter控制器中$_POST
变量始终为空:
controllers / Register.php
class Register extends CI_Controller
{
public function index()
{
$this->load->view('register.html');
}
public function user()
{
var_dump($_POST);
}
}
views / register.html(查看)
<form method="post" role="form" action="register/user">
<div class="form-group">
<label for="email">Name:</label>
<input type="text" class="form-control" id="name">
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
这是我的.htaccess
,我正在使用它从我的网址中删除index.php
。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
var_dump($_POST)
始终输出array(0) { }
,但$_GET
正常。我在Linux(Arch)上使用Apache,Codeigniter 3和PHP 7。
抱歉我的英文。谢谢大家。
编辑:
$this->input->post()
也是空的。
答案 0 :(得分:3)
The main cause is name
attributes from all the form-elements
are missing
Like for example:-
<input type="text" class="form-control" id="name">
It seems you confused between id
and name
.
name
is the attribute picked-up by $_POST
.