Multipul Bits of Information in a Form

Hi All

I’m having troubles getting my head around how to do this…

I have a website that sells tshirts. Basically you can buy the different styles in different colours and sizes.

In my form I have the item number, item name etc however I need to work out how to do the colour, size and qty all in one go.

Imagine the item is a short sleeve shirt and you can buy black, white, red, blue and yellow in S, M, L and XL and you can buy as many as you want in one go.

So I have this big form/table that looks like this: (the 0’s are text boxes)

         S      M      L      XL

Black 0 0 0 0

White 0 0 0 0

Red 0 0 0 0

Blue 0 0 0 0

Yellow 0 0 0 0

Someone can order say 5 Black S, 3 Red M, 4 Blue L and so on in one go and then click add to cart. The adding to the cart part I’m all good with if I can pass al the information over.

So my question is how would I go about passing in the information to my code to update the database.

Currently I just have <input type=‘text’ name=‘qty’ size=‘2’> for each colour and size which clearly won’t work.

I thought of adding the information into the field such as Black||S and Black||M and so on but a text field will not hold that information. I also thought about adding a hidden field but that won’t work either as you can’t tie the 2 fields together.

Any help or suggestions on how I can achieve this would be great.

Many Thanks

mrmbarnes

I would use arrays. Something along the lines of:


<input type="text" name="qty[black][s]" />
<input type="text" name="qty[black][m]" />
<input type="text" name="qty[black][l]" />
<input type="text" name="qty[black][xl]" />

<input type="text" name="qty[white][s]" />
<input type="text" name="qty[white][m]" />
<input type="text" name="qty[white][l]" />
<input type="text" name="qty[white][xl]" />


foreach($_POST['qty'] as $color=>$colorInfo)
{
  foreach($colorInfo as $size=>$qty)
  {
     echo $qty.' ordered of size '.$size.' in color '.$color.'<br />';
  }
}

HTH :slight_smile:

Perfect; thanks