2

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.

asked Jul 28, 2016 at 20:16
5
  • 2
    I'm betting that the CI framework is intercepting the $_POST and converting it to $this->input->post(). Try var_dump($this->input->post());. In CI 3 you have the option of allowing $_GET in the config file. codeigniter.com/user_guide/libraries/input.html Commented Jul 28, 2016 at 20:18
  • 1
    I tried that before, same problem. Commented Jul 28, 2016 at 20:21
  • 6
    @vaati name attributes for all the form elements are missing that is problem Commented Jul 28, 2016 at 20:23
  • 1
    OMG i can't believe. Sorry guys. Commented Jul 28, 2016 at 20:26
  • 1
    It is all ways good i think to use baseurl in action="<?php echo base_url('register/user');?>" make sure you have set base_url as it is required to do so in CI3 versions autoload the url helper Commented Jul 28, 2016 at 22:53

1 Answer 1

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.

answered Jul 28, 2016 at 20:26
Sign up to request clarification or add additional context in comments.

2 Comments

Also check the action="register/user" attribute on the form element. If anything attempts to redirect to add an ending slash to register/user/, it will drop the POST variables.
I changed my answer. I was answering another question and typed part of it here.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.