I've spent most of today trying to work out why my CodeIgniter application returns empty $_POST
(and $this->input->post(<var>)
and php://input
) - I'd reduced the application down to a utterly minimal example of a single form input element and echoing $_POST
.
As requested, the files (but, as far as I can see, this is irrelevant to my question of why the lack of the .htaccess
rules prevents POST data being submitted through the framework):
The controller was this:
<?php
class Form extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('form');
$this->output->enable_profiler(TRUE);
}
public function form_show() {
$this->load->view("form");
}
public function data_submitted() {
$data['user_name'] = $this->input->post('u_name');
$this->load->view("form-success", $data);
}
}
?>
form(.php) was:
<html>
<head></head>
<body>
<?php
echo form_open('Form/data_submitted');
echo form_label('User Name :', 'u_name');
$form_data = array('name' => 'u_name');
echo form_input($form_data);
$submit_data = array(
'type' => 'submit',
'value'=> 'Submit',
);
echo form_submit($submit_data); ?>
echo form_close();
if(isset($user_name)){
echo "<p>".$user_name."</p>";
} ?>
</body>
</html>
form-success(.php) was
<?php var_dump($this->_ci_cached_vars); ?>
<html>
<head></head>
<body>
<?php print_r($_POST); ?>
</body>
</html>
I then realised I didn't have a .htaccess in my root folder - so restored CodeIgniter's default .htaccess file of
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
But I can't work out which one of these (or why) allows POSTed data to be passed to the controller, but removing these rules doesn't allow it. Any light anyone can shed on this would be hugely appreciated to help satisfy my curiosity!