...

View Full Version : Reading Multiple Select Box values with PHP



ReadMe.txt
10-13-2003, 11:12 PM
Not sure whether this is an obvious thing i'm missing or what, but here's my prob:

i'm making a forum search and i need the users to be able to select multiple options, i've built the form and when it is submitted the querystring looks lke this:

query=search+terms&type=AND&case=1&forums=0001&forums=0025&forums=0027&field=post&submit=Search

which is good, only problem is, when i dump the contents of $_GET, i get this:

array(7) { ["query"]=> string(12) "search terms" ["type"]=> string(3) "AND" ["case"]=> string(1) "1" ["forums"]=> string(4) "0027" ["field"]=> string(4) "post" ["submit"]=> string(6) "Search" }

As you can see, i only get the last value for the forum ID, any ideas on how to get all the other ones as well?

michael.hd
10-13-2003, 11:27 PM
You cant give 3 values to forums variable and expect the progrem to remember them all.

You need forums1, forums2, forums3, etc then all of them will be stored.

missing-score
10-14-2003, 07:54 AM
When you have more than one reference to a form value, the latest will overwrite the oldest, so try this.

<form method="get">

<select name="forums[]" multiple="multiple">

<option value="0001">Forum 1</option>
<option value="0025">Forum 2</option>
<option value="0027">Forum 2</option>

</select>

</form>

and then an ARRAY of the selected values sould be available through the $_GET['forums'] variable.

try:

var_dump($_GET['forums']);

to check it works.

ReadMe.txt
10-14-2003, 09:43 PM
Originally posted by michael.hd
You cant give 3 values to forums variable and expect the progrem to remember them all.

You need forums1, forums2, forums3, etc then all of them will be stored.

right then, u seem to be missing the point somewhat, missing-score is right on the money, it hit me the next morning and i dunno why i didn't think of it myslef lol. Ty for the help ppl.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum