How to post two values in an option field?

You cannot post two values unless both of them appear in the value attribute. You can place both in, separated by a comma or hyphen and explode() them apart in PHP:

// Place both values into the value attribute, separated by "-"
<option value="<?php echo $name['id'] . "-" . $name['name']);?>">
   <?php echo $name['name']);?>
</option>      

Receiving them in PHP

// split the contents of $_POST['data'] on a hyphen, returning at most two items
list($data_id, $data_name) = explode("-", $_POST['data'], 2);

echo "id: $data_id, name: $data_name";

Leave a Comment