I am having some trouble with a multi-select form…
Below is the code for the form. I am using the POST method. I have MUTIPART/FORM-DATA set. I have the name using []. But still, when I submit the page and try to view the submission, it comes up blank…
<form action="biomes" method="post" enctype="multipart/form-data">
<input type="hidden" name="submitted" value="1">
<select name="biome[]" class="input-sel" multiple size="8" >
<option value="" class="optcol1 opthead" disabled >-- Select Multiple --</option>
<option value="BiomeGra">Grasslands</option>
<option value="BiomeFor">Forest</option>
<option value="BiomeMou">Ocean</option>
<option value="BiomeMou">River</option>
<option value="BiomeJun">Jungle</option>
<option value="BiomeDes">Desert</option>
<option value="BiomeSav">Savannah</option>
<option value="BiomeSwa">Swamp</option>
<option value="BiomeSno">Snow</option>
<option value="BiomeMou">Mountain</option>
<option value="BiomeCav">Caves</option>
</select>
<button type="submit" class="redbut smallbut">Change</button>
</form>
And here is how I try to view the results once submitted … which come up blank…
$biome = $_POST['biome'];
echo "Biome Array: ";
print_r($biome);
I’ve search all over the place, and most of the time everyone has issues with the []. Or they dont include "multiple" in the SELECT tag. Other times, they submit with POST and try to "GET" the value. Or, they confusing a variable with an array. I think I have addressed all that… Not sure what is going wrong…
(Note sure why stackoverflow is showing most of my code as orange, after the multiple declaration … I assume sttackoverflow just doesn’t know how to handle "multiple" since it doesn’t have an equal or quotes)
>Solution :
Change the action attribute to point to your PHP script and it should work.
action="my-biome-script.php"
I tested it locally and your code works as-is after I made that change.