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'])) {

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:


//init variables  
$cf = array();  
$sr = false;
$st = false;

$ur = false;

    $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.

Edited by eternalhour: Better clarification

5 Years
Discussion Span
Last Post by eternalhour

what's wrong with a html reset button?

<input type="reset" value="Reset" />

A reset button doesn't work because I'm holding onto the field data in session variables, nothing happens. I should also clarify that the only field that is not resetting is the field I have mentioned. All others reset properly.

Edited by eternalhour


how about try to insert some javascript into your into your html.
on your <head></head> part insert a jquery.
then add this code to your head after your jquery.


in this part everytime you click on that certain button it will execute this code that will reset your form.


Ultimately what the reset is doing, is destroying the variables. Unfortunately JQuery is not the solution here.

Edited by eternalhour


I ended up figuring this out. The probem was here:

header('location: ' . $_SERVER['HTTP_REFERER']);

After the variable was passed, the querystring was still in the URI, so when I reset the form it was referring me back to the same page and passing the variable again. Changed the location to the absolute address of the contact form and problem solved.

Edited by eternalhour

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.