Code:
<html>
<head>
</head>
<form method="POST" action="<?php echo $PHPSELF; ?>">
<p>
<input type="checkbox" name="C1" value="ON" checked>Option1</p>
<p>
<input type="text" name="T1_1" size="20" value="123" maxlength="1" readonly></p>
<p>
<input type="text" name="T1_2" size="20" value="124" readonly></p>
<p>
<input type="checkbox" name="C2" value="ON" checked>Option2</p>
<p>
<input type="text" name="T2_1" size="20" value="453" readonly></p>
<p>
<input type="checkbox" name="C3" value="ON">Option3</p>
<p>
<input type="text" name="T3_1" size="20"></p>
<p>
<input type="text" name="T3_2" size="20"></p>
<p>
<input type="submit" value="Button" name="B1"></p>
</form>
<?php
if (isset($_POST))
{
/*
echo "<p>You selected:</p>";
if (isset($_POST['C1']))
{
echo "<p>Option1</p>"
.$_POST['T1']."<br>"
.$_POST['T2']."<br>";
}
if (isset($_POST['C2']))
{
echo "<p>Option2</p>"
.$_POST['T3']."<br>";
}
if (isset($_POST['C3']))
{
echo "<p>Option3</p>"
.$_POST['T4']."<br>"
.$_POST['T5']."<br>";
}
echo "<hr>";
//That works (with old controls), but is rather static; the following would be dynamic if you continue to name the controls the same...(T1, T2, TX), (C1, C2, CX), etc
for ($i=0;$i<count($_POST);$i++)
{
if (isset($_POST["C".$i]))
{
echo "<p>Option$i</p>"
.$_POST["T".$i]."<br>";
}
} */
//This only halfway works, so....
//If you named the controls like T1.1, you can group any number of controls to a single check box
//Number the checkboxes like C1, C2, CX, and textboxes like T1.1, T1.2, T1.3 [all w/C1], T2.1 [C2], TX.X [CX, any number])
for ($i=0;$i<count($_POST);$i++)
{
if (isset($_POST["C".$i]))
{
echo "<p>Option$i is ".$_POST["C".$i]."</p>";
for ($j=0;$j<count($_POST)-$i;$j++) //not extremely efficient, but I'm not going to take the time to speed it up (use explode to separate out and speed up)
{
if (isset($_POST["T".$i."_".$j]))
{
echo $_POST["T".$i."_".$j]."<br>";
}
}
}
}
}
?>
</body>
</html>