vaati vaati - 4 months ago 42
PHP Question

Global POST always empty

the

$_POST
varyable is always empty in my Codeigniter controller:

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 (view)

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


That is my
.htaccess
, i'm using it to remove
index.php
from my URL.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


var_dump($_POST)
always output
array(0) { }
, but
$_GET
works fine. I'm on Linux (Arch), using Apache, Codeigniter 3, and PHP 7.

Sorry for my english. Thanks for all.

Edit:

$this->input->post()
is empty too.

Answer

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.

Note:-

If problem still persist then try @b-bub solution.thanks