checkbox names aggregate as array in a hidden input value
Hey all, I asked this around the chatroom and got some good feedback, but ultimately I couldn't get this to work.
In a form, I have multiple checkboxes which represent products whose values are the product prices and names are the product names. When a user clicks submit the next page processes it for cart/purchase purposes.
I need to pass the names of each checkbox to the next page as an array, and it seemed the best way to accomplish this would be to have a hidden input which automatically generates that array in the page then gets passed to the next (via POST) so the application can manipulate the data.
My server-side language is PHP on Codeigniter.
Here's the code:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
- <title>hidden input issue</title>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
-
- <script type="text/javascript" charset="utf-8">
- //Some jQuery...
- </script>
- </head>
- <body>
- <form action="shop/add_to_cart" method="post" accept-charset="utf-8">
- <p><input type="checkbox" name="Product 1" value="31" />Product 1</p>
- <p><input type="checkbox" name="Product 2" value="54" />Product 2</p>
- <p><input type="checkbox" name="Product 3" value="12" />Product 3</p>
- <p><input type="checkbox" name="Product 4" value="28" />Product 4</p>
-
- <p><input type="hidden" name="hidden_array" value="" /></p>
- </form>
- </body>
- </html>
Any help would be appreciated. I'm also open to suggestions as to how else I might accomplish this.