0

I've following HTML code:

<form action="rebates.php" role="form" method="post">
<select id="example28" multiple="multiple" name="applicable_states">
    <option value=""  selected='selected'>Select Unit</option>
    <option value="1" >Alabama</option>
    <option value="2" >Alaska</option>
    <option value="3" >Arizona</option>
    <option value="4" >Arkansas</option>
    <option value="5" >California</option>
 </select>
<button type="submit" class="btn btn-primary">Preview</button>
</form>

The JQuery code for select control is as follows:

/*jQuery Code*/
 $(document).ready(function() {
    window.prettyPrint() && prettyPrint();
     $('#example28').multiselect({
         includeSelectAllOption: true,
         maxHeight: 150
     });
 });

I've used Bootstrap's js and css (Multiselect and Prettify) to achieve this. My issue is I'm not getting the checked elements' values after submission of form in $_POST array oe rebates.php. Can someone please help me in this regard? Thanks in advance. When I check some values from the select control and submit the form I'm getting the $_POST array as follows:

Array
(
 [applicable_states] => 11
 [multiselect] => 11
)

Why this is happening? The code in rebates.php is as follows:

<?php
print_r($_POST); die;
?>
PHPLover
  • 1
  • 51
  • 158
  • 311

1 Answers1

1

PHP needs to know it's an array. So you need to change the name of the select.

name="applicable_states[]"
Ryan Kinal
  • 17,414
  • 6
  • 46
  • 63