Welcome Guest, Not a member yet? Register   Sign In
storing form_multiselect items in db
#1

[eluser]boony[/eluser]
Hi Guys,

I've got a form that needs to allow multiple selections (either checkbox or dropdown). But I'm a bit confused as to how to process this once the user submits their choices and store the choices in the database.

Here is an example of the select form field in the view...
Code:
<select multiple="multiple" id="idCue" name="idCue[]" class="asmselect" size="1" title="Select any that match">
                  <option value="size">Size</option>
                   <option value="body colour">Body colour</option>
                   <option value="position of dorsal fin">Position of dorsal fin</option>
                   <option value="blow shape and size">Blow shape and size</option>
                   <option value="other">Other</option>
            </select><br />

I think I can do this using the new form_multiselect but the userguide is a little confusing. The 3rd parameter is used to pass an array for items to be selected, but what if I don't want anything selected to start with???

Code:
$options = array('size'=>'size',
                 'body colour'=>'body colour',
                 ...
                 );
echo form_multiselect('idCue[]', $options, ???);

Now, I'm not sure how to process this and to insert the selected options into the db.

If anyone has some hints how to best handle this it would be a great help.

Cheers
#2

[eluser]bigtony[/eluser]
You could initially pass an empty array if you don't want anything selected by default. When it comes to process in your controller, the value in $this->input->post('idCue') will be an array, so just foreach through the elements and update your db however you need.




Theme © iAndrew 2016 - Forum software by © MyBB