I have come up with a way to pass variables from one from to the next. Please could you advise to whether you think there is a better way to do it than this:
<?php
//Build the sections
//Section 1
Function S1Q1(){
global $PHP_SELF;
print("<form name=\"form1\" method=\"post\" action=\"$PHP_SELF\">
Section 1<hr> <br>
Do you play computer games? <br>
Yes
<input type=\"radio\" name=\"S1Q1\" value=\"Yes\">
No
<input type=\"radio\" name=\"S1Q1\" value=\"No\">
<br><br>
Why dont you play computer games? (More than one can be selected)
<br>
They are boring<br>
<input type=\"checkbox\" name=\"S1Q2\" value=\"S1Q2(A)\">
<br>
They are too expensive<br>
<input type=\"checkbox\" name=\"S1Q2\" value=\"S1Q2(B)\">
<br>
I have better things to do with my time<br>
<input type=\"checkbox\" name=\"S1Q2\" value=\"S1Q2(C)\">
<br>
<input type=\"submit\" name=\"Submit\" value=\"Submit\">
<input type=\"hidden\" name=\"stage\" value=\"2\">
</form>");
}
//Section 2
Function S2Q1(){
global $question1;
global $S1Q1;
global $S1Q2;
global $PHP_SELF;
print("<form name=\"form1\" method=\"post\" action=\"$PHP_SELF\">
Section 2 <input type=\"text\" name=\"question2\">
<input type=\"hidden\" name=\"question1\" value=\"$question1\">
<input type=\"hidden\" name=\"S1Q1\" value=\"$S1Q1\">
<input type=\"hidden\" name=\"S1Q2\" value=\"$S1Q2\">
<input type=\"submit\" name=\"Submit\" value=\"Submit\">
<input type=\"hidden\" name=\"stage\" value=\"3\">
</form>");
}
// Determine the sections to diplay
switch ($stage) {
case "2":
S2Q1();
break;
case "3":
print("<form name=\"form1\" method=\"post\" action=\"$php_self\">
Question 3 <input type=\"text\" name=\"question3\">
<input type=\"submit\" name=\"Submit\" value=\"Submit\">
<input type=\"hidden\" name=\"stage\" value=\"3\">
</form>");
break;
case "done":
Print("Thank You for your answers");
break;
default:
S1Q1();
}
?>
Also i want to build in a way to only pass the hidden variables that are selected:
They are boring<br>
<input type=\"checkbox\" name=\"S1Q2\" value=\"S1Q2(A)\">
<br>
They are too expensive<br>
<input type=\"checkbox\" name=\"S1Q2\" value=\"S1Q2(B)\">
<br>
I have better things to do with my time<br>
<input type=\"checkbox\" name=\"S1Q2\" value=\"S1Q2(C)\">
For example if "They are boring" and "They are too expensive" where selcted then i would only want these passed.
Any ideas.