Welcome Guest, Not a member yet? Register   Sign In
multi select form
#1

[eluser]selftaught[/eluser]
When I select multiple choices and hit submit there is only one element in the POST array. Can anyone see anything obviously wrong with my code below?

Thank you

Code:
contorller
<?php

class Form extends CI_Controller {

    function index()
    {
            $this->load->helper(array('form', 'url'));

            $this->load->library('form_validation');
            
            $this->form_validation->set_rules('market', 'Market Choice', 'required');

            if ($this->form_validation->run() == FALSE)
            {
                    $this->load->library('template');
                    $this->template->load('default','header','inventory');                        
            }
            else
            {
                    $this->load->view('formsuccess');
            }
    }
}
?>

<p>
Hello world! This is where I will put the inventory form..
</p>


form
&lt;?php
$post  = array('MCI'   => 'Kansas City',
    'LIN'   => 'Lincoln',
    'OMA'   => 'Omaha',
    'ICT'   => 'Wichita',
    );
?&gt;

&lt;?php echo validation_errors(); ?&gt;
&lt;?php echo form_open('form'); ?&gt;

&lt;?php
echo form_fieldset('Choose Market(s)');
echo form_multiselect('market', $post);
echo "<p>Query results will be displayed below.</p>\n";
echo form_submit('mysubmit', 'Submit Query');
echo form_fieldset_close();

formsuccess.php
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Form&lt;/title&gt;
&lt;?php echo ("<pre>".print_r($_POST,true)."</pre>"); ?&gt;

&lt;/head&gt;
&lt;body&gt;

<h3>Your form was successfully submitted!</h3>

<p>&lt;?php echo anchor('/home/inventory', 'Try it again!'); ?&gt;</p>

&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]Aken[/eluser]
You need to name it with array notation.

Code:
form_multiselect('market[]', $post);

You also don't close your form, which you should.
#3

[eluser]InsiteFX[/eluser]
Try adding form_close
Also you are missing the third parameter
Code:
echo form_multiselect('market[]', $post, 'LIN');

Is just like form_dropdown




Theme © iAndrew 2016 - Forum software by © MyBB