Welcome Guest, Not a member yet? Register   Sign In
Form Multiselect
#1

[eluser]boytun[/eluser]
Hello.

Please, can some one help me to know how to create a standard multiselect field with form_multiselect(), and how to fetch the values to store them in the database.

Thanks in advance
#2

[eluser]TheFuzzy0ne[/eluser]
That's a subject that doesn't seem to be covered in much detail in the user guide. Here's what I've come up with.

Code:
<?php
    echo form_open();
    
    $options = array(
        'Option 1',
        'Option 2',
        'Option 3',
        'Option 4',
        'Option 5',
    );
    
    $defaults = array(
        1,
        3,
    );
    
    echo form_multiselect('my_select[]', $options, (isset($_POST['my_select'])) ? $_POST['my_select'] : $defaults);
    
    echo form_submit('submit', 'Submit');
    
    echo form_close();
?>

I admit, it does seem a bit awkward, and the existing helper/documentation could definitely use some improvement.

To get an array of selected values:
Code:
$my_values = $this->input->post('my_select');
#3

[eluser]boytun[/eluser]
Thanks a lot Smile




Theme © iAndrew 2016 - Forum software by © MyBB