Yes.
On the file that is processing the request you want to make sure that you have session_start(); at the top of the file, and in the case that the form inputs are invalid or blank you use the following line of code:
<?
$_SESSION['formfields'] = array();
foreach($_POST as $key=>$value)
{
$_SESSION[$key] = $value;
$_SESSION['formfields'][] = $key;
}
$_SESSION['formfields'] = NULL;
unset($_SESSION['formfields']);
?>
Then on your form for text fields including text boxes and textareas you consult the following example
//text box
<input type="text" name="fname" id="fname" value="<? echo isset($_SESSION['fname'])?$_SESSION['fname']:$originalvalue; ?>" />
//text area
<textarea name="description" id="description"><? echo isset($_SESSION['fname'])?$_SESSION['fname']:$originalvalue; ?></textarea>
for select drop downs
<select name="selState" id="selState">
<option<? echo isset($_SESSION['selState']) && $_SESSION['selState'] == "AZ"?' selected="selected"':""; ?> value="AZ">AZ</option>
<option<? echo isset($_SESSION['selState']) && $_SESSION['selState'] == "CO"?' selected="selected"':""; ?> value="CO">CO</option>
<option<? echo isset($_SESSION['selState']) && $_SESSION['selState'] == "AK"?' selected="selected"':""; ?> value="AK">AK</option>
<option<? echo isset($_SESSION['selState']) && $_SESSION['selState'] == "ME"?' selected="selected"':""; ?> value="ME">ME</option>
</select>
for multi-select drop downs
<select name="selState[]" id="selState">
<option<? echo isset($_SESSION['selState']) && in_array("AZ", $_SESSION['selState'])?' selected="selected"':""; ?> value="AZ">AZ</option>
<option<? echo isset($_SESSION['selState']) && in_array("CO", $_SESSION['selState'])?' selected="selected"':""; ?> value="CO">CO</option>
<option<? echo isset($_SESSION['selState']) && in_array("AK", $_SESSION['selState'])?' selected="selected"':""; ?> value="AK">AK</option>
<option<? echo isset($_SESSION['selState']) && in_array("ME", $_SESSION['selState'])?' selected="selected"':""; ?> value="ME">ME</option>
</select>
for radio buttons and check boxes
//check boxes
<input type="checkbox"<? echo isset($_SESSION['chkColors']) && in_array("red", $_SESSION['chkColors'])?' checked="checked"':""; ?> name="chkColors[]" id="chkColorsred" value="red" /> <label for="chkColorsred">Red</label><br />
<input type="checkbox"<? echo isset($_SESSION['chkColors']) && in_array("green", $_SESSION['chkColors'])?' checked="checked"':""; ?> name="chkColors[]" id="chkColorsgreen" value="green" /> <label for="chkColorsgreen">Green</label><br />
<input type="checkbox"<? echo isset($_SESSION['chkColors']) && in_array("blue", $_SESSION['chkColors'])?' checked="checked"':""; ?> name="chkColors[]" id="chkColorsblue" value="blue" /> <label for="chkColorsblue">Blue</label><br />
<input type="checkbox"<? echo isset($_SESSION['chkColors']) && in_array("purple", $_SESSION['chkColors'])?' checked="checked"':""; ?> name="chkColors[]" id="chkColorspurple" value="purple" /> <label for="chkColorspurple">Purple</label><br />
//radio buttons
<input type="radio"<? echo isset($_SESSION['rdoColors']) && $_SESSION['rdoColors'] == "red"?' checked="checked"':""; ?> name="rdoColors" id="rdoColorsred" value="red" /> <label for="rdoColorsred">Red</label><br />
<input type="radio"<? echo isset($_SESSION['rdoColors']) && $_SESSION['rdoColors'] == "green"?' checked="checked"':""; ?> name="rdoColors" id="rdoColorsgreen" value="green" /> <label for="rdoColorsgreen">Green</label><br />
<input type="radio"<? echo isset($_SESSION['rdoColors']) && $_SESSION['rdoColors'] == "blue"?' checked="checked"':""; ?> name="rdoColors" id="rdoColorsblue" value="blue" /> <label for="rdoColorsblue">Blue</label><br />
<input type="radio"<? echo isset($_SESSION['rdoColors']) && $_SESSION['rdoColors'] == "purple"?' checked="checked"':""; ?> name="rdoColors" id="rdoColorspurple" value="purple" /> <label for="rdoColorspurple">Purple</label><br />
On the top of your form you also want to put
When ever you want to clear the form fields from your session variables just run this code.
<?
foreach($_SESSION['formfields'] as $value)
{
$_SESSION[$value] = NULL;
unset($_SESSION[$value]);
}
$_SESSION['formfields'] = NULL;
unset($_SESSION['formfields']);
?>
That should cover just about everything, let me know if something doesn't work quite the way it should.