I have a small form on a page that opens with several radio buttons on. The labels of these buttons changes every time the page loads, which is fine. However, there is a condition in the code that when the button is pressed, checks to make sure the radio buttons have been clicked. If they have not been clicked then I want the page to reload again with an error message (which it does) and put the label of the buttons back exactly how they were. My code currently stands at this:
session_name(activeTest);
session_start();
$test1= new Test(); //Create new test instance
$test1->init(); //Initialise the test instance
//Set the option 1 session
$_SESSION['option1'] = $test1->option1;
$form['url'] = $_SERVER['PHP_SELF'];
if (isPostBack())
{
if (checkForm() == false) //Check form checks to make sure radio buttons have been pressed and returns false if they have not been
{
$test1->option1 = $_SESSION['option1'];
echo ("You have not answered all the questions");
include_once("templates/test.html");
}
}
else
{
include_once("templates/test.html");
//If form not being posted, just display the page
}
function isPostBack()
{
return (isset($_POST['action']));
}
In test.html, the labels next to the radio buttons are specified as $test1->option1 etc depending on option number, so there is no problem with the HTML. I know that maybe a little confusing, it is to me. Please help as I am completely new to this. Thanks.