steve m Posted November 25, 2007 Share Posted November 25, 2007 Hello, I have a question on how to pass information from a form. I am building a simple order form for this site. I am not using a database because the person that this is for doesn't want to use a database. On the form I built a function to display the different type of products taken from the array. Each product has a Qty box and when I loop the array I put a counter in it so I can name the Qty, type, and price fields. Example: qty0, type0, price0 - qty1 etc... <?php function ListDonuts() { $flavors = array(Glazed => "0.76", Chocolate => "0.80", White . " " . Sprinkles => "1.20", Chocolate . " " . Sprinkles => "1.25", Red . " " . Velvet => "2.00", Peanutbutter . " " . Chocolate => "2.50"); $item_count = count($flavors); echo $item_count; $i = 1; $j = 0; $columns = 2; foreach($flavors as $type => $price) { if($i == $columns) { $class = "class='form-colb'"; $i = 1; } else { $class = "class='form-cola'"; $i++; } $showTypes .= "<div $class> <p class='dis-donut-list'> <input class='input-box' type='textbox' name='qty$j' value='$qty' size='1' /> <input type='hidden' name='type$j' value='$type' /> <input type='hidden' name='price$j' value='$price' /> <input type='hidden' name='item_count' value='$item_count' /> $type -- $$price </p> </div>\n"; $j++; } return $showTypes; } ?> All this is fine until I submit the form. I want to be able to only select the product items that have a quantity in the qty field. This is where I am coming up blank. I've tried making the "qty" field an array (qty[]) (this is not in the above function)and then doing a foreach loop to pull the information, but I don't know how to pass the "type" and "price" values to the qty[] array to display it on the confirmation page or to save it to a CSV file. So that is why I came up with the above function. I thought I could just name the those fields with the counter and get the info that way, but I want to efficient about that and not have a lot of IF statements depending on how many items are in the array, because that number can change. Would any body be able to help me with this problem? Am I making this harder than it really is? I am totally having a brain freeze! Thanks! Quote Link to comment 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.