Welcome Guest, Not a member yet? Register   Sign In
this->input() as array?
#1

[eluser]A.M.F[/eluser]
hello everybody,

i am trying to build a three-steps registration. each time a user finish to complete one form he is redirecting to the next one.
so, each time when he submit one form, i want to insert the data to sessions (so the user would be able to go back in the forms and change his data if he wants to).

so, how can i put the data of the inputs or the validation fields inside a session?
(i don't want to use $_POST)

thank u!

-btw: is there any simpler way u seguesst?
#2

[eluser]Michael Wales[/eluser]
Code:
$this->session->set_userdata(array('answer1'=>$this->input->post('answer1'), 'answer2'=>$this->input->post('answer2')));
#3

[eluser]A.M.F[/eluser]
[quote author="Michael Wales" date="1197338188"]
Code:
$this->session->set_userdata(array('answer1'=>$this->input->post('answer1'), 'answer2'=>$this->input->post('answer2')));
[/quote]

isn't there a way just to put one name of an array like this:
Code:
$this->session->set_userdata($_POST)
i don't want to do it like this cuz it's not safe enough
#4

[eluser]A.M.F[/eluser]
thx for the help but in the end i did a function that get's $_POST as an array and puts this array after beeing secured inside another array, and then i am putting it inside a sesion.
like this:

Code:
function make_arr_session($arr, $name)
{
    $object =& get_instance();
    
    $data = Array();

    foreach($arr as $k=>$v)
    {
        $data[$k] = $object->input->post($k, TRUE);
    }
    
    $object->session->set_userdata(array($name => $data));
}
#5

[eluser]Michael Wales[/eluser]
I'm not really sure how that is anymore secure... all you are doing is providing one more layer of arrays to dive through. If someone were to submit a bogus form, their field/values would still be submitted and inserted into the session.

Maybe something like this:

Code:
function make_arr_session($arr, $name)
{
    $object =& get_instance();
    
    $data = Array();
    $valid_fields = array('username', 'email', 'password');

    foreach($arr as $k=>$v)
    {
        if (in_array($k, $valid_fields)) {
            $data[$k] = $object->input->post($k, TRUE);
        }
    }
    
    $object->session->set_userdata(array($name => $data));
}

This way - the only thing going into the session is what you pre-approve and are expecting from the form.
#6

[eluser]A.M.F[/eluser]
thank u, u helped me. before i saw ur reply i rewrite my function and it was like this:

Code:
function make_arr_session($arr, $name, $trash = '')
{
    $object =& get_instance();
    
    $data = Array();
    $dump = FALSE;

    foreach($arr as $k=>$v)
    {
        if ($trash != '') {
            foreach($trash as $field)
            {
                if ($field == $k) //we don't need the field?
                {
                    $dump = TRUE;
                }
            }
        }
        
        if (!$dump)
        {
            $data[$k] = $object->input->post($k, TRUE);
        }

        $dump = FALSE;
    }
    
    $object->session->set_userdata($name, $data);
}



but then i saw (thanks to u) that instead of using foreach twice, i can just use in_array. thank u!




Theme © iAndrew 2016 - Forum software by © MyBB