By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

Multiple Get's ...

P: 3
Okey .. so , i have a problem ... in one of my forms i have this element:
[HTML]
<select name="list" multiple="multiple" size="10" >
<option value="Opt1">Opt1</option>
<option value="Opt2">Opt2</option>
<option value="Opt3">Opt3</option>
<option value="Opt4">Opt4</option>
</select>
[/HTML]
The user can and will select multiple items.
I see that when the form is submited the selected variabiles are passed like this:

page.php?list=Opt1&list=Opt2


How can i get through GET or POST all the selected options in the form after the user submits the form ?
Feb 4 '07 #1
Share this Question
Share on Google+
5 Replies


Motoma
Expert 2.5K+
P: 3,235
Okey .. so , i have a problem ... in one of my forms i have this element:
[HTML]
<select name="list" multiple="multiple" size="10" >
<option value="Opt1">Opt1</option>
<option value="Opt2">Opt2</option>
<option value="Opt3">Opt3</option>
<option value="Opt4">Opt4</option>
</select>
[/HTML]
The user can and will select multiple items.
I see that when the form is submited the selected variabiles are passed like this:

page.php?list=Opt1&list=Opt2


How can i get through GET or POST all the selected options in the form after the user submits the form ?
Welcome to The Scripts.
The tata elements will be in an array named $_POST['list'].
Run a print_r() on it to see what it looks like.
Feb 4 '07 #2

P: 3
Doesn`t work ..

i use GET in the form instead of POST for the moment to see if the values are passed .. and they are

page.php?list=Opt1&list=Opt2&....

But the print_r only get's first variabile ..
Feb 4 '07 #3

Motoma
Expert 2.5K+
P: 3,235
Doesn`t work ..

i use GET in the form instead of POST for the moment to see if the values are passed .. and they are

page.php?list=Opt1&list=Opt2&....

But the print_r only get's first variabile ..
Try using POST instead.
Feb 4 '07 #4

P: 3
Okey .. POST and GET are the same with the difference that POST doesn't give the chance of simple users to "play" with pages ( aka more secure for the site ).


I don`t think many of you know .. i've been searching a lot more and I found the answer .. So when you use a select with multiple options you have to cheat to let php recognize it.

When processing the request, php puts all selected options in the select object's name, but treats it like an array. If it is not an array, only the last option is remembered.

So to cheat you should append [ ] to the name of the select

<form .. ... ..>
<select multiple="multiple" name="myselect[]" size="3">
<option value="1">1st option</option>
<option value="2">2nd option</option>
<option value="3">3rd option</option>

...

Then in the processing part:
<?php
if(!empty[$_REQUEST['myselect']) print_r($_REQUEST['myselect']);
?>
Feb 4 '07 #5

Motoma
Expert 2.5K+
P: 3,235
Glad you were able to find your own answer.
Thanks for posting it back to us.
Feb 4 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.