Posted by Daz on 11/04/06 16:55
T. Wintershoven wrote:
> Can anyone help me solve this problem.
Another solution might be this:
if (!isSet($_POST['submit']))
{
ShowForm();
}
else
{
HandleForm();
}
// Declare the question array in the global scope.
$question=array();
$question[0]="100";
$question[1]="125";
$question[2]="150";
$question[3]="175";
$question[4]="200";
function ShowForm() {
global $question;
echo"<form name='form1' method='post'
action='".$_SERVER['PHP_SELF']."'>";
for($i=0; $i<5; $i++) {
// This time we are making a unique name for the checkbox
// (i.e question_1, question_2 etc...).
echo "<input type='checkbox' name=$question_$i> This is the "
."question with ID ". $question[$i]."<br/>";
}
echo "<BR><input type='submit' name='submit' value='Show
choice'>";
echo"</form>";
}
function HandleForm() {
global $question;
for($i=0; $i<5; $i++) {
// Create the name for the checkbox we can't to check.
$question_name = "question_".$i;
// This may not be a legit method, but by adding '2' dollar
signs to the beginning
// of the variable, the variable name is correctly parsed as it
should be.
if(isset($_POST[$$question_name])) {
echo "Question ".$_POST[$question[$i]]." was "
."ticked.<br/>";
}
}
}
I haven't tested it, but I hope you get the idea.
[Back to original message]
|