NMLcygni
NMLcygni

Reputation: 71

How to make a select-multiple send an array

I have a form that looks like this:

<form method="post" action="action.php">
   <select id='select' multiple='multiple'>
     <option value="1"> Option1 <option>
     <option value="2"> Option2 <option>
   </select>
</form>

My problem here is that this code only sends one(the last) option if both Options are selected to the action.php. Is there a way to make it send both options if both are selected? What am i missing?

Upvotes: 2

Views: 3878

Answers (1)

rjdown
rjdown

Reputation: 9227

Your select doesn't have a name attribute, so it wouldn't send anything at all. I'm going to assume that's a copy-paste error.

To return an array, you just need to set the name as an array, e.g.

<select id='select' multiple='multiple' name='yourname[]'>

(note the [])

Upvotes: 4

Related Questions