tags:

views:

1441

answers:

4

I've got a form that I'm handling with PHP. Before the user submits it, the Reset button works. But when they submit and the page reloads (I've made the form fields sticky based on the $_POST values) the reset doesn't work. How can I fix that? EDIT: For example, a checkbox on the form:

 <input type="checkbox"  <?php if (isset($_POST['cb12'])){echo 'checked="checked"';} ?> name="cb12" tabindex="34" id=cb value="Education">

And the HTML:

<tr>
          <td colspan="5" valign="top" class="addit" ><div class="sectionbreak topsp" >
              <input type="hidden" name="failure" value="failure.html" >
              <p>
                <input type="submit" name="Submit" value="Submit" tabindex="49">
                Sends your application by email to The Boggs</p>
              <p>
                <input type="reset" name="Reset" value="Reset" tabindex="50">
                Clears all the fields</p>
            </div></td>
        </tr>

EDIT: In the end, I just hid the button if the form has been submitted (but isn't complete). Maybe no one will notice.

+4  A: 

You could react to the reset event with an unset($_POST).

tharkun
+6  A: 

Do you really need reset button?

I haven't seen in my life any form that would benefit from it (i.e. where user would like to instantly and irreversibly lose all data he just entered).

porneL
Erm, maybe because it's part of a spec she has to follow? How is this a helpful answer?
da5id
It's helpful, because if (possibly useless) reset button is removed, the problem will disappear with it.
porneL
It is part of a spec. I've thought about removing the button after the first submit, but I doubt I can get away with it.
lynn
+4  A: 

The reset button undoes changes to the form, made by the user, it doesn't erase default values. If you want to erase all default values, you could use JavaScript to do something like:

<script type="text/javascript">
   function resetForm(myFormId)
   {
       var myForm = document.getElementById(myFormId);

       for (var i = 0; i < myForm.elements.length; i++)
       {
           if ('submit' != myForm.elements[i].type && 'reset' != myForm.elements[i].type)
           {
               myForm.elements[i].checked = false;
               myForm.elements[i].value = '';
               myForm.elements[i].selectedIndex = 0;
           }
       }
   }
</script>

...

<form id="myFormId" ...>

<input name="reset" type="reset" onclick="resetForm('myFormId'); return false;" />

...

Ch4m3l3on
+1  A: 

I've just been through this exact thing, see my previous question & the incredible helpful answers.

In the end I had to do a manual reset of the values in PHP.

EDIT: Not quite the same scenario for you as you seem to be populating the form values based on $_POST rather than $_SESSION as I did. In which case, see the answer I accepted via the link above.

da5id
Solution is jQuery, though. = /
rlb.usa