2

I am getting a strange behaviour.

In a view in Codeigniter I have this code:

<?php echo form_multiselect('post-categories', $active_categories, (!empty($selected_categories))?$selected_categories:null,array('class'=>'form-control')); ?>

Which generates the following HTML

<select name="post-categories" class="form-control" multiple="multiple">
<option value="1">Beauty</option>
<option value="4">More</option>
<option value="3">New</option>
</select>

However when I submit the form with multiple categories selected I receive only strings.

In the controller

var_dump($this->input->post('post-categories'));

will output

string(1) "3"

Is there something I am doing wrong or missing?

1 Answer 1

1

The name should be post-categories[] (array syntax). Try -

form_multiselect('post-categories[]', $active_categories, (!empty($selected_categories))?$selected_categories:null,array('class'=>'form-control'));
Sign up to request clarification or add additional context in comments.

Comments

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.