Welcome Guest, Not a member yet? Register   Sign In
foreach on $this->input->post(), is it possible?
#1

[eluser]LAMP Coder[/eluser]
I need to do following using $this->input->post()

Code:
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

Is a foreach loop possible on the input class?
#2

[eluser]davidbehler[/eluser]
If you call the method without an argument it returns FALSE, atleast as far as I remember.
You would have to extend the Input class to return the post array instead of FALSE.

Instead of extending the class, you can do as you said in your example and use the $_POST array. That should work just fine.
#3

[eluser]LAMP Coder[/eluser]
I thought of that as well... I was just wondering if it's possible without extending the input class.
#4

[eluser]sheldonnbbaker[/eluser]
I was needing this functionality as well.

This simple function works (I extended the CI_Input library), but am not sure if it's the best way of doing it:

Code:
function posts() {
        
        $posts = array();
        
        foreach($_POST as $key => $value) {
            
            $posts[$key] = $this->post($key);
            
        }
        
        return $posts;
        
    }
#5

[eluser]Jamie Rumbelow[/eluser]
You might also want to call xss_clean() on every value, to stop any nasty things getting in! It's especially important to sanitise your data when you're inserting it into the database, or displaying it to the user. Heck, you should sanitise your data anyway, it's good practice and anything that comes from the outside could be a potential risk to your application's security.

Jamie
#6

[eluser]sheldonnbbaker[/eluser]
[quote author="Jamie Rumbelow" date="1260161320"]You might also want to call xss_clean() on every value, to stop any nasty things getting in! It's especially important to sanitise your data when you're inserting it into the database, or displaying it to the user. Heck, you should sanitise your data anyway, it's good practice and anything that comes from the outside could be a potential risk to your application's security.

Jamie[/quote]

Ah - thought that was done automagically :/

Whenever I call $this->input->post('post_name'), do I need to add TRUE to the $xss_clean parameter?
#7

[eluser]Jamie Rumbelow[/eluser]
You can set global_xss_filtering to TRUE in your config file to turn it on, and the filter will run on everything, or you can pass TRUE to the post(), get() and server() functions and the filter will run on the values they return.

Jamie
#8

[eluser]Namaless[/eluser]
Good Idea... add this to CI php5 wrapper :-)




Theme © iAndrew 2016 - Forum software by © MyBB