Working with Forms in PHP, Part 1
Subject:   Checkboxes
Date:   2005-03-30 15:00:39
From:   mgiroir

I have a php form that I created and I have checkboxes that are populated using a mysql table. Everything populates just fine but when I submit the form I do not get the exact results that I want. Code follows:

// Populate array
$equipmentnames[] = $equipment['equipmentname'];
// Output checkboxes
echo '<input name="product' . $equipment['equipmentid'] . '" type="checkbox" value="' . $equipment['equipmentname'] . '" />';
echo '' . $equipment['equipmentname'] . ' @ ' . $equipment['equiprentalprice'] . '';

echo '<input name="product' . $equipment['equipmentid'] . 'price" type="hidden" value="'. $equipment['equiprentalprice'] . '">';

What I want to do is this. When the form is submitted, I need the product fields filled with the equipmentname variable taken from the table. This works just fine, but when the form is submitted variables get put into each of the product price fields. I know that this is because of the hidden input, but cannot figure out how to change it, so that when the equipment is not selected the product price will be set to 0.00 or NULL. Could I use an if statement either inside the form or inside the processing.php file that would specify a distinction between whether the item equipment is checked or unchecked. I did read see something about isset or whatever but couldn't figure out where to put it or how to use it. An assistance would be greatly appreciated.