View Full Version : How do I clear form data upon submission?

04-Mar-2009, 03:25 AM
I just downloaded and set up the FormMail script, and so far it works fine. My question is, I want to clear the form when it is submitted, before the page is redirected. Either that or prevent the browser from going back to the form with all the data still in it. Basically, I'm trying to avoid making it easy to do multiple submissions in quick succession. Is there any way to do that with the FormMail settings? I'm new to PHP. I was trying to do it with the location.replace() in JavaScript, but so far that's not working. I'm still learing JS too, and I'm not sure what all the FormMail script is doing or how it interacts with the scripts, etc. in the form.

04-Mar-2009, 09:58 PM

You can't stop browsers from doing what they think users should be able to do. Like go back to a form page and resubmit it.

Having said that, we are planning a new feature to ward of other types of attacks such as many multiple submissions from the one IP address.

This is really to protect against bots, though, not against real people.

If you manage to clear the form before submission, no fields will be sent to your server and the form submission will be blank.

You could try to clear the form on page display (it's the "onload" attribute in the <form> tag), but that probably won't work if they go back after submitting the form.

Having said all that, we do have a new feature in FormMail that lets you set a session variable in PHP.

If you convert your HTML form page into a PHP script, it could set the session variable and then prevent form submissions if that is already set.

That's quite complex work though, so you'll need a PHP programmer to achieve it.

04-Mar-2009, 11:17 PM
Thanks, russellr, for the reply. I did find a way to do it with JavaScript, using "onunload" and "location.replace()" in the body tag. It basically redirects to the specified page, like the "good_url", but without allowing the user to use the back button. The form I'm using it for gives the user a randomly generated coupon number at submission, and I figured sooner or later someone would find out they could hit the back button and re-submit multiple times to guarantee themselves a permanent discount. :eek: :D They could still navigate back to the page, but this makes it a little more difficult. There's probably a better way to set the whole thing up, but I'm just doing this for a project as I'm learning JavaScript right now, so it's not a real issue. I still like to learn as much as I can, though, so thanks for the help. That new feature sounds like it would be useful for something like this too.