I have an exam and what I am looking to do use session to save every value, whether it's textboxes or selects or radio button groups choices. So if the user submits the form and misses something, coming back to the form from a different page, it keeps all the value that was entered and auto fills it in. I would also like to keep the session alive for 2 hours. I know I can use something of the following:
FORM PAGE:
<form method=post action="submit.php">
<input type=text value="" name="first" />
<input type=radio value="A" name="acct" /> A
<input type=radio value="B" name="acct" /> B
<input type=radio value="A" name="birt" /> A
<input type=radio value="B" name="birt" /> B
</form>
On submission of the form in the submit.php
page I have this:
<?php
session_start();
$_SESSION['textbox1'] = isset($_POST[first]) ? $_POST[first] : null;
$_SESSION['radiogroup1'] = isset($_POST[acct]) ? $_POST[acct] : null;
$_SESSION['radiogroup2'] = isset($_POST[birt]) ? $_POST[birt] : null;
** PLUS OTHER CODES I USE **
?>
The above should start a session and save those values so no matter if I exit the page or not, it should store it. Correct?
Now questions I have are:
- How do I make the session alive for ONLY 2 hours
- Let's say I exit the page or go to another page and I come back to the FORM page, how do I auto enter the value which was originally saved in the session?
- In WHAT SHOULD I ENTER HERE How do I accomplish, if the user selected a value fill it in otherwise leave it alone? SOLVED
I really appreciate the help.