Hi Daniwebbers,
I've created a web form and code in order to reset/clear the form with a button. However, in a specific circumstance, the form only resets properly if I go to a separate page then come back to the form and reset it. It only happens directly after I have passed a variable from another page to the form. I will try to lay this out.
Here is the reset code from my form processing page:
if(isset($_POST['reset'])) {
session_start();
unset($_SESSION['cf_returndata'], $_SESSION['report']);
header('location: ' . $_SERVER['HTTP_REFERER']);
}
The variable in question is "$_SESSION['report']."
Here is the code from my form page:
session_start();
//init variables
$cf = array();
$sr = false;
$st = false;
$ur = false;
if(isset($_SESSION['cf_returndata'])){
$cf = $_SESSION['cf_returndata'];
$sr = true;
$st = true;
}
//Check if URL was passed
if(isset($_GET['report'])) {
$_SESSION['report'] = $_GET['report'];
}
if(isset($_SESSION['report'])) {
$report = $_SESSION['report'];
$ur = true;
$st = false;
}
if(isset($cf['errors']) && count($cf['errors']) == 0) {
unset($_SESSION['cf_returndata'], $_SESSION['report']);
}
And the code from the field itelf which as you can see is two ternary operators in conjunction:
value="<?php echo ($ur && isset($_SESSION['report'])) ? $report : ''; echo ($st && !$cf['form_ok']) ? $cf['posted_form_data']['url'] : ''; ?>"
Any suggestions I can get on this is much appreciated as it is the last minor hurdle before I publish the site.