Storing multiple inputs with the same name in a CodeIgniter session

I posted this in the CodeIgniter forum and also exhausted the forum search engine, so I apologize if the cross-wiring frowned.

Essentially, I have one input configured as <input type="text" name="goal">. At the request of the user, they can add another target that issues a duplicate in the DOM. What I need to do is to capture these values ​​in my CodeIgniter controller and save them in a session variable. Currently, my controller is designed this way:

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);
}

, , , , . , .

, , , , $this- > input- > posts ('goal'). . .

, .

+3
1

:

<input type="text" name="goal[]">

:

$goal = $this->input->post('goal');

:

$this->session->set_userdata('goal', $goal);

. :

$goal = $this->session->userdata('goal');

- :

$goal[0] = 'first goal';
$goal[1] = 'second goal';

, :)

+6

Source: https://habr.com/ru/post/1746101/


All Articles