Jump to content

[SOLVED] Preventing Double Posts on a form


arianhojat

Recommended Posts

I saw this article which helps out:

http://www.bigtrapeze.com/double_post/postblock.php

 

I get how it posts a random hidden form # on each page, and if its the same as the last submitted form(kept track of via session variable), it tells you its a double post (or you can put some code in to redirect to another page).

 

I was also wondering how to stop pressing the submit button twice. i dont think this postBlock class catches that.

My only guess is to disable the submit button, onsubmit.

Link to comment
https://forums.phpfreaks.com/topic/48983-solved-preventing-double-posts-on-a-form/
Share on other sites

You want Javascript.

 

Something like

 

<script type="text/javascript">
function disableButton(button) {
      button.enable = false;
      button.value = "Processing...";
}
</script>

<input type="submit" value="Submit!" onClick="disableButton(this);" />

 

I am not sure if the code is correct or will work, but yea.

 

http://javascript.internet.com would be a great resource for find working code.

My only guess is to disable the submit button, onsubmit.

 

That's what I typically do. Of course you can never count on the fact that all users will have javascript enabled, but most do. So, the risk is much smaller. For those who don't you have several options:

 

1. Do not allow them to submit/use the form if javascript is not enabled (e.g. do not have a true submit button, use javascript to submit)

 

2. Create some back-end functionality as you stated to identify duplicates

 

3. Do nothing. This is a valid solution depending upon the situation. If it is a form to create a user account there should be validation to prevent a duplicate from being created. however, if it is an ordering page you don't want to allow the user to place two orders.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.