scrbowler Posted February 3, 2008 Share Posted February 3, 2008 Help! I'm trying to setup a form with a drop down where a person will select multiple (5 to be exact) items from the list and then submit the form. How do I assign a specific variable to each selection on submit? thank you Steve Quote Link to comment https://forums.phpfreaks.com/topic/89230-variables-in-a-multiple-select-drop-down/ Share on other sites More sharing options...
Aureole Posted February 3, 2008 Share Posted February 3, 2008 You can do it with an array I think, it has something to do with putting "[]" somewhere in the input element... then it will become a sub-array of the $_POST array. That's all I can think of, at any rate. I've never done it before so I can't really help. Quote Link to comment https://forums.phpfreaks.com/topic/89230-variables-in-a-multiple-select-drop-down/#findComment-456899 Share on other sites More sharing options...
pocobueno1388 Posted February 3, 2008 Share Posted February 3, 2008 You need to create an array for these values, so here is an example. HTML <form> <select name="choices[]" multiple="multiple"> <option>...</option> <option>...</option> <option>...</option> <option>...</option> <option>...</option> <option>...</option> </select> </form> Now when they submit the form, all the selected values will be in the array $_POST['choices'] Quote Link to comment https://forums.phpfreaks.com/topic/89230-variables-in-a-multiple-select-drop-down/#findComment-456902 Share on other sites More sharing options...
scrbowler Posted February 3, 2008 Author Share Posted February 3, 2008 How do I get a variable assigned seperately to each choice? I need each to be handled seperately in the next stage. Quote Link to comment https://forums.phpfreaks.com/topic/89230-variables-in-a-multiple-select-drop-down/#findComment-456934 Share on other sites More sharing options...
pocobueno1388 Posted February 3, 2008 Share Posted February 3, 2008 Just grab them straight from the array. From the HTML example I posted above, to get the first value you would use choices[0], and so on. Or you could use a foreach loop, it all depends on what your trying to do. So if this doesn't help you, explain more. Quote Link to comment https://forums.phpfreaks.com/topic/89230-variables-in-a-multiple-select-drop-down/#findComment-456937 Share on other sites More sharing options...
scrbowler Posted February 4, 2008 Author Share Posted February 4, 2008 I've been giving this the ole college try and nothing seems to work for what I want when it comes to assigning a variable to the results of the form. As you see in the code below I have a couple of efforts to make the variable available to the array list but I can't get it to post using the examples below. Any help in assigning the variables to the choices will be greatly appreciated. I'm trying to use the variables $driver1, $driver2 .... and so forth for the 5 selections from the form. thanks Steve <form name="entry" method="post" action="<? echo $PHP_POST; ?>"> <select name="choices[]" multiple="multiple"> <option><input type="radio" name="#48 Jimmie Johnson" value="48" />#48 Jimmie Johnson</option><br> <option><input type="radio" name="#24 Jeff Gordon" value="24" />#24 Jeff Gordon</option><br> <option><input type="radio" name="#07 Clint Bowyer" value="107" />#07 Clint Bowyer</option><br> <option><input type="radio" name="#17 Matt Kenseth" value="17" />#17 Matt Kenseth</option><br> <option><input type="radio" name="#5 Casey Mears" value="5" />#5 Casey Mears</option><br> <option><input type="radio" name="#20 Tony Stewart" value="20" />20 Tony Stewart</option><br> <option><input type="radio" name="#77 Sam Hornisch Jr." value="77" />#77 Sam Hornisch Jr.</option><br> <option><input type="radio" name="#31 Jeff Burton" value="31" />#31 Jeff Burton</option><br> <option><input type="radio" name="#99 Carl Edwards" value="99" />#99 Carl Edwards</option> </select> <input type="submit" name="submit" value="Send" /> </form> <? $ID=array($_POST, $choices, "choices[2]", "choices[3]", "choices[4]"); //trying 3 diff attempt for values but no luck for($count = 0; $count < sizeof($ID); $count++) { $IDarray[]=$ID[$count]; } foreach($IDarray as $key => $val) { print("$key -- $val<br />"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89230-variables-in-a-multiple-select-drop-down/#findComment-458028 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.