-1

I have a form on my website where one can select multiple other editors for a post. The list of qualified editors is echoed by PHP, which works. But when multiple are selected HTML makes it into one list of the ids. F.E. If Jay (id = 4) and Sam (id = 9) are selected. The received value will be $_POST['editors'] = 49.

My code:

<select multiple class="editors" name="editors" id="editors">
    <?php
      //Gebruikers ophalen
      $editorArr = getEditors();
      foreach($editorArr as $editor){
        echo "<option value='".$editor['id']."'>".$editor['email'].' - '.$editor['type']."</option>";
      }
    ?>
 </select>

and the handling PHP

      $editors      = htmlentities($_POST['editors']);
Demiën Drost
  • 174
  • 1
  • 3
  • 14
  • 2
    Possible duplicate of [How to get multiple selected values of select box in php?](http://stackoverflow.com/questions/2407284/how-to-get-multiple-selected-values-of-select-box-in-php) – Flakes Mar 11 '16 at 13:04

1 Answers1

3

Okay! Try this:

<select class="editors" name="editors[]" id="editors" multiple>
<?php
    //Gebruikers ophalen
    $editorArr = getEditors();
    foreach ($editorArr as $editor) {
        echo "<option value='".$editor['id']."'>".$editor['email'].' - '.$editor['type']."</option>";
    }
 ?>
 </select>

The name should be an array so it can treat all selected values separately.

Hope it helps

awoyotoyin
  • 792
  • 4
  • 8