0

I have php form which has numerous check boxes. I need to store all the selected check boxes in an array and then use them from my controller. So far, in my controller I have

$data['categories']= array($this->input->post('category'))

where my check boxes are called "category". however this method is only storing a single check box value, even when numerous check boxes are selected.

I then intend to pass this array to a model for processing.

Thank you for the help, I appreciate any suggestions.

2 Answers 2

1

In your view, use category[] as a name for checkboxes.

Example:

<input type="checkbox" name="category[]" checked> Option 1
<input type="checkbox" name="category[]" checked> Option 2
etc...
Sign up to request clarification or add additional context in comments.

Comments

0

In your view

<td><input type="text" name="category[]"/></td>
<td><input type="text" name="category[]"/></td>
<td><input type="text" name="category[]"/></td>

Notice, we added two brackets, to indicate that this is an array.

Then in your Controller you can loop through it or whatever you like.

foreach ( $this->input->post('category') as $category)
{
// some stuff here
}

1 Comment

Thanks this worked perfectly, the full array is being passed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.