phplaravellaravel-3

Getting selected values from a multiple select form in Laravel


For generating a drop-down list with an item selected by default, the following is done:

echo Form::select('size', array('L' => 'Large', 'M' => 'Medium', 'S' => 'Small'), 'S');

So I generated a drop-down list that has more than one item selected by default, in the following way:

echo Form::select('size', array('L' => 'Large', 'M' => 'Medium', 'S' => 'Small'), array('S', 'M'), array('multiple'));

But how do I get the more than one selected values?

Input::get('size') returns only the last selected string.


Solution

  • First, if you want to have multiple item selected by default, you have to give an array of values as 3rd parameter, not a simple value.

    Exemple:

    Form::select('size', array('L' => 'Large', 'M' => 'Medium', 'S' => 'Small'), array('S', 'M'), array('multiple'));
    

    should show the select with S and M selected.

    For the second point, you should try to give a name like size[] instead of size, it could be solve the problem (because your posted select is not a simple value, its an array of values)