-1

Help I want to get value from a multiple select dropdown from a form to a controller.

Here's my form:

<select multiple="multiple" id="form-field-select-4" class="form-control search-select" name="tim_teknis">
    <option value="">&nbsp;</option>
    <option value="AL">Alabama</option>
    <option value="AK">Alaska</option>
</select>

And here's my controller:

$tim_teknis = $_POST['tim_teknis'];

It turned out to be showed like this: "tim_teknis" not the value of the dropdown. I hope anyone could understand what I mean. Thank you!

Community
  • 1
  • 1

2 Answers2

-1

You have to implode the values before insert

Janki Rathod
  • 107
  • 6
-1

May be your form not method is 'POST' , so "tim_teknis" not the value of the dropdown. Solution:

<form action="submit_form.php" method="POST"><select multiple="multiple" id="form-field-select-4" class="form-control search-select" name="tim_teknis[]"><option value="">&nbsp;</option><option value="AL">Alabama</option><option value="AK">Alaska</option></select></form><?php if (!empty($_POST['tim_teknis'])) {var_dump($_POST['tim_teknis']);}?>

Result after submit form: array(2) { [0]=> string(2) "AL" [1]=> string(2) "AK" }

Duong Tu
  • 19
  • 4