Thank you NogDog, you are right, my question was not very clear.
Johanafm, I have tried the nested switch a few times and it does seem to work as you say, however...
This may seem like a simple question now but I can't get my answer variable into the page switch. I now have $q for the question and $a for the answer. So my question (previously page) switch look slike this:
// Validate what page to show:
if (isset($_GET['a'])) {
$a = $_GET['a'];
} elseif (isset($_POST['a'])) { // Forms
$a = $_POST['a'];
} else {
$a = NULL;
}
// Validate what page to show:
if (isset($_GET['q'])) {
$q = $_GET['q'];
} elseif (isset($_POST['q'])) { // Forms
$q = $_POST['q'];
} else {
$q = NULL;
}
// Determine what page to display:
switch ($q) {
case 'q01_01':
$page_title = 'Question 1.1';
switch($a) {
case '1':
$page = 'questions/q01_01.inc.php';
break;
case '2':
$page = 'questions/q01_02.inc.php';
break;
case '5':
$page = 'questions/q01_10.inc.php';
break;
}
default:
$page = 'questions/q01_01.inc.php';
break;
case 'q01_02':
$page = 'questions/q01_02.inc.php';
$page_title = 'Question 1.2';
break;
case 'q01_03':
$page = 'questions/q01_03.inc.php';
$page_title = 'Question 1.3';
break;
case 'q01_10':
$page = 'questions/q01_10.inc.php';
$page_title = 'Question 1.10';
break;
case 'register':
$page = 'register.inc.php';
$page_title = 'Register';
break;
case 'activate':
$page = 'activate.inc.php';
$page_title = 'Activate';
break;
case 'login':
$page = 'login.inc.php';
$page_title = 'Login';
break;
case 'logged_in':
$page = 'logged_in.inc.php';
$page_title = 'Login';
break;
case 'logout':
$page = 'logout.inc.php';
$page_title = 'Logout';
break;
case 'change_password':
$page = 'change_password.inc.php';
$page_title = 'Change password';
break;
case 'forgot_password':
$page = 'forgot_password.inc.php';
$page_title = 'Forgot password';
break;
// Default is to include the main page.
default:
$page = 'main.inc.php';
$page_title = 'Survey';
break;
} // End of main switch.
// Make sure the file exists:
if (!file_exists('./modules/' . $page)) {
$page = 'main.inc.php';
$page_title = 'Survey';
}
// Include the header file:
include_once ('includes/header.html');
// Include the content-specific module:
// $page is determined from the above switch.
include ('./modules/' . $page);
// Include the footer file to complete the template:
include_once ('includes/footer.html');
?>
I have hard-coded the $q variable into the GET array and my problem now is how to get the POST array to include my $a variable. Here is my question page with the form:
if (isset($_POST['submitted'])) { // Handle the form.
if(isset($_POST['q01_01_00'])) {
$a = escape_data($_POST['q01_01_00']);
} else {
$a = NULL;
}
// Add the data to the responses table.
$query = "UPDATE responses SET q01_01_00='$a' WHERE response_id=$rid";
$result = @mysql_query ($query); // Run the query.
}
?>
<div id="content">
<form action="<?php echo $_SERVER['PHP_SELF'] . '?q=q01_01'; ?>" method="POST">
<fieldset>
<legend>Section 1: Background</legend>
<p>Question 1.1 What is your marital status?</p>
<p>
<input type="radio" name="q01_01_00" value="1" checked="yes" /><label for="q01_01_00">Single, never married</label><br />
<input type="radio" name="q01_01_00" value="2" /><label for="q01_01_00">Married and living with spouse</label><br />
<input type="radio" name="q01_01_00" value="3" /><label for="q01_01_00">In a Civil Partnership and living with a partner</label><br />
<input type="radio" name="q01_01_00" value="4" /><label for="q01_01_00">Living with partner</label><br />
<input type="radio" name="q01_01_00" value="5" /><label for="q01_01_00">Divorced, separated or widowed</label><br />
</p>
<p>
<input type="hidden" name="submitted" value="TRUE" />
<?php echo '<input type="hidden" name="rid" value="' . $rid . '" />';?>
<input type="submit" value="Next" />
</p>
What should I do to get the $a variable posted? As it stands, it is not available until the page is posted and then it is too late.