Page 1 of 1
Dealing with a form select that alows multiple entries
Posted: Thu Jan 15, 2004 3:42 pm
by LazarusCrusader
I have a form with a select field that alows multiple selections. How do I get all of the selected info when the form is posted?
I've tried this but got an error:
Code: Select all
foreach($_POSTї'StateDesired'] as $value)
{
$desired .= $value . ", ";
}
Any ideas?
Posted: Thu Jan 15, 2004 4:12 pm
by markl999
Presuming your form contains something like..
<select name="StateDesired[]" size="5" multiple>
then you can use :
if(!empty($_POST['StateDesired'])){
echo join(', ', $_POST['StateDesired']);
}
Posted: Thu Jan 15, 2004 5:06 pm
by LazarusCrusader
Getting this error with your code:
Warning: join(): Bad arguments
Posted: Thu Jan 15, 2004 5:13 pm
by markl999
Hmm..shouldn't do, if you have name="StateDesired[]" in the form, then it comes in as an array. The if(!empty checks to make sure 'something' was selected, and the join operates on the StateDesired array.
Maybe post a snippet of your code? (including the select form element)
Posted: Thu Jan 15, 2004 5:36 pm
by LazarusCrusader
Got it... had to correct my syntax...
Thanks a bunch!