tags:

views:

259

answers:

6

Hi.

I just implemented a sendmail in PHP called from a html page with a form. It requires filling some textfields, then pressing the submit button causing the mail to be sent. So far so good.

Now I need this form to be cleared on successful mail transmission.

My guess is that Internet Explorer (or other) saves all field values when moving on to another page. This makes it easy to go back in browser history and resend the mail. What I want is that on a succesful transmission of the mail the form cache (or whatever) is cleared. This must be done in the PHP page called.

Has anyone got a clue how to solve this?

A: 

Make the form page uncachable and the client will request it every time.

Gumbo
A: 

If the only problem is being able to read the form by using the back button:

window.onunload=function(){for(var i=0;i<document.forms.length;i++){document.forms[i].reset()}}

This assumes that using the form will not unload/leave the page.

Coding With Style
+1  A: 

Is this what you are talking about?

SO393882 - Cross-browser techniques for disabling password caching

Although they talk about username/password stuff mostly, i think any of those techniques could prevent what you need to prevent for your form. Particularly the solutions that involves hashing/altering the input field's names, and simply autocomplete=off in your <input> tag.

gnarf
A: 

You could submit the form via AJAX and on success send back Javascript which clears all form fields.

Josh
A: 

Also, check with your users if they really want their painstakingly entered data to disappear. Especially if they expect their back buttons to take them back to a step in the process where they need to correct an error (e.g. wrong email address).

chlechte
A: 

Hi all, and thanks for the massive response!

gnarf - it seems somebody asked for just that i was after: something like a "cache=off" option...

Gumbo - I tried to make all my pages uncacheable, since I have some copyrighted photos on my page, but the cache seems to remain anyway... and that would definitely cut off any chance to recover what was written in the form in any case.

Coding With Style - This came closest to a solution! Tried the function out, but I got no result pressing the back arrow in Internet Explorer.

Josh - Have no experience with AJAX. How can I use it?

chlechte - well, it was my intention to clear the cache when and only when the mail was successfully sent i.e. in the PHP sendmail page, not in the form page calling the sendmail page. This means that if a sender forgot a mail address, he is then notified, and can press the back button coming back to the form untouched.

Writing all this an idea came into my mind. Would it be possible to on exit clear the cache as "Coding With Style" said and on error have a manufactured back button that feeds the form with what was enterred, letting this button appear if the mail was not sent by any reason?

cheers!!!