New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$_POST and $this->input->post() are empty #242
Comments
I have used TAMPER DATA firefox plugin and the data is sent correctly. In controller there aren't data. |
Not sure I completely understand the problem but when you say 'I send data in some forms' - I take it you're speaking of the HTML forms you use to submit a post request? Have you tried adding $this->output->enable_profiler(); to your controller to see what is passed (if anything) to $_POST? Also, what's the 'error' you get? |
Yes, HTML forms. |
Try adding this line to the top of your index.php file and seeing what the output is:
If you still don't get any POST data, the problem is with your form or your server, not CodeIgniter. |
Agreed with jamierunbelow - I was thinking the same initially. Please paste the code for your form. |
@jamierumbelow, this is the output:
|
@chrisberthe, this is de php code:
And this is the generaed html code:
|
Judging from what the $_POST returned, the array contains appropriate values and isn't empty. So the issue is something related to your application (my guess it's something in your backoffice controller and how you're manipulating that $_POST data), not CodeIgniter itself. If anything, you can create your own repository, push your current project and we'll have a look from there. |
The project is not mine and I can't upload to a public repository. I'm sorry. This is the login method from backoffice controller:
|
The problem lies with your controller. Make sure you run a check on the form submission to see whether or not the form passed validation using: $this->form_validation->run() == FALSE You should also set some rules for each of your fields. Everything you need for form validation can be found in the CodeIgniter documentation located here: http://codeigniter.com/user_guide/libraries/form_validation.html. |
as chrisberthe said, this looks to be a controller issue, not a CI issue. So closing this one out. |
I don't think so. The project works in a server but not in my laptop. |
@chrisberthe, I tried |
|
I tested the code both locally and remotely - works fine for me. Try this for both your controller and view, respectively: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Backoffice extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->output->enable_profiler(TRUE);
$this->load->helper('url_helper');
$this->load->library('form_validation');
$this->load->library('session');
}
public function index()
{
redirect('backoffice/login', 'refresh');
}
public function login()
{
if ($this->input->post('action') == 'backoffice.login')
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$data['username'] = $username;
$data['password'] = $password;
}
$data['title'] = 'Wtf Title';
$this->load->view('backoffice/login', $data);
}
} <!DOCTYPE html>
<head><title><?php echo $title; ?></title></head>
<body>
<?php echo form_open('backoffice/login','id="loginForm"'); ?>
<fieldset>
<legend><b>Login Form</b></legend><br>
<span style="font-size: 1.5em"><?php echo (isset($username) AND isset($password)) ? $username .' / '. $password : ''; ?></span>
<p>Please enter your credentials</p>
<input class="txt required email" type="text" name="username" value="" onfocus="if($(this).val() == 'Email') $(this).attr({value:''});" onblur="if($(this).val() == '') $(this).attr({value:'Email'});"/><br/>
<input class="txt required" type="password" name="password" value="" onfocus="if($(this).val() == 'Password') $(this).attr({value:''});" onblur="if($(this).val() == '') $(this).attr({value:'Password'});"/><br/>
<div style="float: left;"><?php echo anchor('backoffice/reset_password', 'Reset Password'); ?></div>
<div style="float: right;"><?php echo form_submit('submit','Login'); ?></div>
<br clear="all"/>
</fieldset>
<input type="hidden" name="action" value="backoffice.login"/>
<?php echo form_close(); ?>
</body>
</html> If there's still a problem, look into your localhost configuration. Sounds like it's the server if it works remotely for you. Also, since this issue is now closed, you're best bet is to move this to the CodeIgniter help forums - you'll have more luck there. |
ok, your code works in my laptop. The problem is the |
I'm not too sure - I'd have to see the rest of the code as it doesn't make sense to me right now. Like I said, you should post your enquiry to the CodeIgniter help forums. You'll have a better chance of finding a solution to your problem as this thread is no longer open here. |
Hi, same issue here. The code worked fine in windows, when I change the environment to Ubuntu, I couldn't get any value passed from my view form. When I use the above suggested methods: die(var_dump($_POST)); and $this->output->enable_profiler(); I get: POST DATA I'm pretty sure my form is ok as I tested it in windows, my question is if this is apache issue, how could I resolve it? |
same problem here |
same problem here too |
Have the same problem. Turned out to be our authenticator failing in such a way that it would just redirect to the login page again and at that point the data was no longer present. |
I have also the same problem, I followed the same above but still problem is not solved. |
I got the solution, that is not CI issue or not a controller issue, its a issue of .htaccess setting. |
For the benefit of others that may experience this, was it a redirect of the request in the .htaccess to a slightly-different URI? For example, if the .htaccess is set up to always append a training slash /, then any POST requests that originally point to the URI without the training slash will be redirected and you'll lose the POST data. Or was it something else? |
You are right, and if Apache server is used then mod rewrite should be On Fri, Jan 18, 2013 at 2:02 PM, The Digital Orchard <
Thanks. Best Regards !! Amit Pandey Mobile :- 9012474075 |
Pandeyamit has it. After a fresh install of WAMP I experienced this problem. The key was enabling mod_rewrite again. |
I have tipical .htaccess for codeigniter, and one particular rule is amking me problems. If it is not commented web doesn't work (can't do any analytics through logs) and if it is comented, it doesn't pass any POST variables. =++++++++++++++++++++++++++++++++++++++++++++++++++++++ RewriteEngine on |
it maybe mod_rewrite was disabled, try type this on your console |
hi.. i got same problem and solved it.. cd /etc/apache2/mods-enabled/locate mod_rewrite/usr/lib/apache2/modules/mod_rewrite.so touch rewrite.loadnano rewrite.load@file: rewrite.load LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so then save... restart your apache... hope it will work at your end. My.Env: Kali Linux (Debian) |
Hi @pandeyamit , You are right ... Its just a URL redirecting issue . I was almost hitting my head for this problem ... My form action url and the redirected url were deffered coz of htaccess . Thank You |
Hi, hoping to save others some time with what I learned. |
Same here. Solved with "sudo a2enmod rewrite" :) |
same problem... same solution :) |
Use the following two command in your terminal
|
When I send data in some forms $_POST is empty in the controller.
The method is POST and de location is right. In the controller I can't get the post values. $this->input->post() is empty as well.
I tried several versions of apache (1.3... and 2.2...).
I tried several versions of php (5.2... and 5.3...).
I tried with the lastest version of codeigniter.
I tried with Mac OS X SnowLeopard and Mac OS X Lion.
I tried with Gentoo (lastest version).
I tried with Windows XP.
I tried with MAMP and WAMP.
The error is the same.
The text was updated successfully, but these errors were encountered: