Jump to content

Multi Select And Loop Trouble


AL156

Recommended Posts

I have been working from O'Rileys php5 book, looping through select menus.That works fine with my single select menus: I post, the values change. But my multiple select menujust prints to the screen and post does nothing. The loop is in function process_form(). Here is my simple site:http://nuke.empireindustry.com/Blogspiracy/Test/index.phpThis is giving me a headache - probably something simple I just don't get.Thanks AL156.<?php // Controller for test Page.include '../config.php';$pizza = array('1' => 'Pepperoni', '2' => 'Canadian Bacon', '3' => 'Meat Medley');$pSize = array('1'=>'Small', '2'=>'Medium', '3'=>'Large');$tMulti = array('1'=>'Extra chese', '2'=>'Canadian Bacon', '3'=>'Sausage', '4'=>'olives');function show_form(){ // start form echo "<form method='post' action='$_SERVER[php_SELF]' > "; // pizza select menu echo "Select a Pizza:<select name='pizza'> "; foreach($GLOBALS['pizza'] as $val => $choice) { print "<option value=\"$val\">$choice</option> \n"; } echo "</select><br /><br /> "; // size select menu echo "Size:<select name='pSize'> "; foreach($GLOBALS['pSize'] as $val => $choice) { print "<option value=\"$val\">$choice</option> \n"; } echo "</select><br /><br /> "; // extra topping menu echo "Extra Toppings:<select name='topMulti[]' multiple='multiple'> "; foreach($GLOBALS['tMulti'] as $val => $choice) { print "<option value=\"$val\">$choice</option> \n"; } echo "</select><br /><br /> "; //end form echo "Order:<input type='submit' NAME='button' value='Verify'> <input type='hidden' name='submit_check' value='1'> </form> ";}function process_form(){ echo "<br />"; echo "Pizza: " . $_POST['pizza']; echo "<br />"; echo "Size: " . $_POST['pSize']; echo "<br />"; if($_POST){ foreach($GLOBALS['tMulti'] as $choice) { echo "you chose $choice <br />"; } } show_form();}if($_POST['submit_check']){ process_form();}else{ show_form();}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...