Welcome Guest, Not a member yet? Register   Sign In
$_POST['var'] isset but $this->input->post('var') returns FALSE
#1

[eluser]ScottBruin[/eluser]
I'm using jQuery's $.load ajax function to send some POST variables. Sometimes, my variable q is set to ''. (That is, I send a jquery object { 'q': '' } with the $.load function.

When I try to load $this->input->post('q') with CI, it returns FALSE. However, if I do something like below, I am told that $_POST['q'] is set
Code:
if (isset($_POST['q'])) { echo 'post is set'; }

According to the user guide for <b>$this->input->post()</b>:
Quote:The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.
Source: http://ellislab.com/codeigniter/user-gui...input.html

What exactly "if the item...does not exist" means is ambiguous at best. For me, I think, I'm trying to retrieve the $_POST item 'q' and it does exist though it has no value.

Also, I just created a test for this without any jQuery involved and the behavior is the same.
Here's the controller I used:
Code:
&lt;?php

class Post extends Controller {

    function Post()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->helper('form');
        echo form_open('post/postissue');
        echo form_input('q', '');
        echo form_submit('mysubmit', 'Submit Post!');
        echo form_close();
            
    }
    
    function postissue()
    {
        echo '<pre>'; print_r($this->input->post('q')); echo '</pre>';
        
        if ($this->input->post('q') != FALSE)
            echo 'q exists for CI too';
        else
            echo 'q does not exist for CI';

        if (isset($_POST['q']))
            echo '<br><br>q is set in post array';
    }

}
?&gt;
#2

[eluser]Seppo[/eluser]
Well... you should use !== instead of !=, because PHP evaluates '' == FALSE as true
#3

[eluser]ScottBruin[/eluser]
Thanks Seppo..did not know that.




Theme © iAndrew 2016 - Forum software by © MyBB