Jump to content
Larry Ullman's Book Forums

Data Is Resubmitted After Page Refresh


Recommended Posts

i think i found the problem. this problem occur because i use the same page to submit a form  by using this code

  } elseif ($values === 'POST') {

so when i do refresh the page it will resubmit the form. i read some book and found that to prevent this to happen is by using HTTP redirect. but i wonder is it any other effective way to prevent this beside using HTTP redirect.

Link to comment
Share on other sites

As far as I know, this is the intended behavior and most sites implement things this way.

Granted, you could do a redirect, but that will make your code more complex and it seems like you're fighting intended and well-known behavior at that point.

 

If you click on the URL bar and hit enter, it'll reload the page without posting the form.

What I can't understand is if you're concerned about this for testing purposes or if you are concerned about your end users.

In other words, what's the problem?

Link to comment
Share on other sites

I'm just afraid if my client which have a slow connection or have connection is interrupted they will refresh the pages. it will cause the data will be resubmitted. I can't say to them to click on URL and hit enter. I know that jQuery will solve this, but what is the trick for PHP if I only use PHP.

Link to comment
Share on other sites

I've seen a lot of sites that put disclaimers near the submit button that say something like the following:

"After clicking Submit, please wait a few moments and please do not click the Back button or close your browser."

 

Beyond that, what can you do?

At this point in the history of the Internet though, I think that people with slow connections have learned not to hit the Back button, etc. when the submit a form.

And if they do hit Refresh or the Back button, what are you going to do if it's PHP only?

There really is nothing.

 

I guess my point is, you can only prevent idiots from hurting themselves to a certain point.

Beyond that, it's not your concern.

Link to comment
Share on other sites

There's no solution in that that is how posting has always functioned in browsers, so it's more something that people (both devs and users) just have to accept.

As you hinted, you can use JS to circumvent things, but that can create other problems too.

Link to comment
Share on other sites

 Share

×
×
  • Create New...