Storing multiple inputs with the same name in a CodeIgniter session

Posted by Joshua Cody on Stack Overflow See other posts from Stack Overflow or by Joshua Cody
Published on 2010-05-19T00:40:23Z Indexed on 2010/05/19 1:20 UTC
Read the original article Hit count: 327

Filed under:
|
|

I've posted this in the CodeIgniter forum and exhausted the forum search engine as well, so apologies if cross-posting is frowned upon.

Essentially, I've got a single input, set up as <input type="text" name="goal">. At a user's request, they may add another goal, which throws a duplicate to the DOM. What I need to do is grab these values in my CodeIgniter controller and store them in a session variable. My controller is currently constructed thusly:

function goalsAdd(){
    $meeting_title = $this->input->post('topic');
    $meeting_hours = $this->input->post('hours');
    $meeting_minutes = $this->input->post('minutes');
    $meeting_goals = $this->input->post('goal');
    $meeting_time = $meeting_hours . ":" . $meeting_minutes;

    $sessionData = array(
        'totaltime' => $meeting_time,
        'title' => $meeting_title,
        'goals' => $meeting_goals
    );

    $this->session->set_userdata($sessionData);
    $this->load->view('test', $sessionData);
}

Currently, obviously, my controller gets the value of each input, writing over previous values in its wake, leaving only a string of the final value. I need to store these, however, so I can print them on a subsequent page.

What I imagine I'd love to do is extend the input class to be able to call $this->input->posts('goal'). Eventually I will need to store other arrays to session values. But I'm totally open to implementation suggestion.

Thanks so much for any help you can give.

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about php