Arrays and forms

From: Date: Sun, 18 Feb 2001 15:03:32 +0000
Subject: Arrays and forms
Groups: php.general 
Request: Send a blank email to php-general+get-40431@lists.php.net to get a copy of this message
Thanks to all the replies to my previous email on arrays (passing arrays through URLs) but I cannot seem to get serialize() to work correctly so I'm now trying to echo out the array as a series of hidden elements in a form that when submitted will re-build the array. I've been driving myself mad with this problem for some time now an I hope that someone can help me with this. I'm trying to insert into a table called options an option_type (eg shape), an option_value (eg square) and product_code (a six digit code). I want this table to be filled from a web form with check boxes (which are called from the same table with a code of XXX so that I know they are possible options for any product). I can do this and have got the code below generated <tr><td colspan='3'><i><b>Colour</b></i></td></tr> <td><input type="checkbox" name="form_options[Colour][]" value="Red">Red</td> <td><input type="checkbox" name="form_options[Colour][]" value="Violet">Violet</td> <td><input type="checkbox" name="form_options[Colour][]" value="Green">Green</td> </tr> <tr> <td><input type="checkbox" name="form_options[Colour][]" value="Blue">Blue</td> </tr> <tr><td colspan='3'><i><b>Size</b></i></td></tr> <td><input type="checkbox" name="form_options[Size][]" value="A3">A3</td> <td><input type="checkbox" name="form_options[Size][]" value="A4">A4</td> <td><input type="checkbox" name="form_options[Size][]" value="A5">A5</td> </tr> From the options table that looks like this: type - value - code colour - red - XXX colour - blue - XXX colour - violet - XXX colour - geen - XXX size - A3 - XXX size - A4 - XXX size - A5 - XXX I think this html form code is right so that when the form is submitted the an array $form_options will be generated now here is my problem: I don't know how to output the array to a html <input type=hidden> fields so that I can safly pass the array form page to page or so that I can then do inserts into the database here is as close as I have gotten : foreach ($form_options as $arrayType){ $i++; $type = ($arrayType[$i]); foreach ($arrayType as $value){ echo("Option :". $type ." Value :". $value . "<br>"); } but this code only produces : Option :Red Value :Red Option :Red Value :Violet Option :Red Value :Green Option :Red Value :Blue Option :A4 Value :A3 Option :A4 Value :A4 Option :A4 Value :A5 I can't seem to find the 'Type' value that should be in the array. Can anyone help me with this code as I DESPERATLY need it. Thanks again Jamie PS sorry for the long winded explaination but I hope I was clear enough in what my aims are.

« previous php.general (#40431) next »