CodeIgniter Forums
input->post() with no parameters should return an array of ALL post data (and the same for get etc) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: input->post() with no parameters should return an array of ALL post data (and the same for get etc) (/showthread.php?tid=16663)



input->post() with no parameters should return an array of ALL post data (and the same for get etc) - El Forum - 03-13-2009

[eluser]fritzthecat[/eluser]
Hi. Unless I am missing something, you can tell CI to give you all the post variables, you have to name the variable you want. It seems odd that I can use the input class to fetch a single variable, and the built in _POST array for cycling through all the vars.
Perhaps input->post() with no variables should return the whole, sanitized, array?

apologies if I'm missing something obvious, I'm pretty new to CI


input->post() with no parameters should return an array of ALL post data (and the same for get etc) - El Forum - 03-13-2009

[eluser]xwero[/eluser]
You can get the array simply by using $_POST. The only reason why you would use the input post method is if you don't clean the globals globally but then you have to set the second parameter to TRUE so how are you going to signal you need the array instead of an item? Input class modification :
Code:
function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
{
    // start modification
    if(strlen($index) == 0)
    {
        if ($xss_clean === TRUE)
        {
            return $this->_clean_input_data($array);
        }

        return $array;
    }        
    // end modification
    if ( ! isset($array[$index]))
    {
        return FALSE;
    }

    if ($xss_clean === TRUE)
    {
        return $this->xss_clean($array[$index]);
    }

    return $array[$index];
}
Only usage that makes sense
Code:
$post = $this->input->post('',TRUE);



input->post() with no parameters should return an array of ALL post data (and the same for get etc) - El Forum - 03-17-2009

[eluser]fritzthecat[/eluser]
$post = $this->input->post('',TRUE);
$post = $this->input->post( null,TRUE);

seems sensible to me