checkbox names aggregate as array in a hidden input value

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:
           
  1.  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4.     <head>
  5.         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  6.         <title>hidden input issue</title>
  7.         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
  8.    
  9.         <script type="text/javascript" charset="utf-8">
  10.             //Some jQuery...
  11.         </script>
  12.     </head>
  13.     <body>
  14.         <form action="shop/add_to_cart" method="post" accept-charset="utf-8">
  15.             <p><input type="checkbox" name="Product 1" value="31" />Product 1</p>
  16.             <p><input type="checkbox" name="Product 2" value="54" />Product 2</p>
  17.             <p><input type="checkbox" name="Product 3" value="12" />Product 3</p>
  18.             <p><input type="checkbox" name="Product 4" value="28" />Product 4</p>
  19.            
  20.             <p><input type="hidden" name="hidden_array" value="" /></p>
  21.         </form>
  22.     </body>
  23. </html>

Any help would be appreciated.  I'm also open to suggestions as to how else I might accomplish this.