I'm trying out CodeIgniter (I'm a novice coder) and am having some trouble with POST data from a form.
I have the following code to generate a form:
<div>
<?php echo form_open('todos/update_completed/'); ?>
<?php foreach ($todos as $todo): ?>
<?php echo form_checkbox('completed', $todo->id, $todo->completed); ?>
<?php echo $todo->task; ?>
<?php echo "<br />"; ?>
<?php endforeach ?>
<br />
<?php echo form_submit('MySubmit', 'Update ToDos'); ?>
<?php echo form_close(); ?>
</div>
This generates the following code:
<form action="http://localhost:8091/index.php/todos/update_completed" method="post" accept-charset="utf-8">
<input name="completed" value="1" type="checkbox">Go to the shops
<br>
<input name="completed" value="2" checked="checked" type="checkbox">Pick up camera
<br>
<input name="completed" value="5" checked="checked" type="checkbox">Call Joey
<br>
<input name="completed" value="6" checked="checked" type="checkbox">Fill in tax return
<br>
<br>
<input name="MySubmit" value="Update ToDos" type="submit">
</form>
When I try to retrieve the POST data using:
$completed_todos = array();
$completed_todos[] = $this->input->post_get('completed');
... I allways get an array ($completed_todos) which only contains 1 (one) element - regardless how many checkboxes I checked, and it is always the latest checkbox I checked!
print_r($completed_todos); only returns the following: Array ( [0] => 6 )
Can someone please explain why I am not getting all the checkbox values returned in my array?
ps: I am following a tutorial from https://selftaughtcoders.com/creating-processing-form-codeigniter/