Im using codeigniter and I have a very simple form, which has a few checkboxes:
<input type="checkbox" name="user_assign[]" value="' . $row->user_id . '">
Now, the values are definately getting posted because I can see them through firebug.
user_assign[]100002
user_assign[]100003
course_name Asbestos
But the below is empty? and i just dont understand?
$user_assign = $this->input->post('user_assign');
How is this possible?
Controller (which is damn messy because I've tried 1001 things)
function update_course_assignment_org() {
$data = $this->input->post('user_assign');
$this->load->model('courses_model');
$this->load->model('assignment_model');
// get course id from posted course name
$course_name = $this->input->post('course_name');
$course_object = $this->courses_model->get_course_id($course_name);
$course_id = $course_object[0]->course_id;
//$user_assign = substr(implode(', ', $this->input->post('user_assign')), 0);
//foreach ($this->input->post('user_assign') as $key => $value) {
$test_obj = array(
'course' => $data,
'users' => $course_id,
'org' => $this->input->post('course_name')
);
//}
//$this->assignment_model->save_org_assignments($user_ids);
$this->template->write('title', 'Assignments');
$this->template->write('navigation_strip', $this->load->view('navigation', array(), TRUE));
$this->template->write('content', $this->load->view('/assignments/assign_test', $test_obj, TRUE));
$this->template->render();
}
View (which is very basic because I've stripped everything down in order to try and get these values through)
<div class="row">
<div class="col-md-4">
<?php var_dump($course); print_r($course); ?>
</div>
<div class="col-md-4">
<?php print_r($users); ?>
<?php print_r($org); ?>
</div>
</div>
The form that contains the checkboxes
<?php echo form_open_multipart('assignments/update_course_assignment_org');?>
<table>
<tr>
<th>User</th>
<th>Assign course</th>
</tr>
<?php
foreach($users as $row) {
echo '<tr>';
echo '<td>' . $row->fname . ' ' . $row->sname . '</td>';
echo '<td><input type="checkbox" name="user_assign[]" value="' . $row->user_id . '"></td>';
echo '</tr>';
}
?>
<tr>
<td>
<input type="hidden" name="course_name" value="<?php echo $course[0]->course_name; ?>">
<input type="submit" value="Assign" />
</td>
</tr>
</table>
</form>