exodia Posted October 1, 2014 Share Posted October 1, 2014 I just notice when i refresh the pages, data that i've entered before is resubmitted. is it because your sticky form function? is it any way to prevent this to happen? thanks. Link to comment Share on other sites More sharing options...
HartleySan Posted October 1, 2014 Share Posted October 1, 2014 I'm not sure what the context is, but if you refresh a page that has been loaded from a posted form, the form will be re-posted. Generally though, your browser will ask you if you want to re-post the form or not in that case. Link to comment Share on other sites More sharing options...
exodia Posted October 1, 2014 Author Share Posted October 1, 2014 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 More sharing options...
HartleySan Posted October 1, 2014 Share Posted October 1, 2014 if (isset($_POST)) Does that work? Link to comment Share on other sites More sharing options...
exodia Posted October 2, 2014 Author Share Posted October 2, 2014 if (isset($_POST)) Does that work? it's the same. i use this code as part of my script too. i think this is the risk using single page to submit and receive form using php. Link to comment Share on other sites More sharing options...
HartleySan Posted October 2, 2014 Share Posted October 2, 2014 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 More sharing options...
exodia Posted October 2, 2014 Author Share Posted October 2, 2014 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 More sharing options...
HartleySan Posted October 2, 2014 Share Posted October 2, 2014 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 More sharing options...
exodia Posted October 3, 2014 Author Share Posted October 3, 2014 I see.. so there's no solution for it except to tell them not to doing it. ok then thanks Hartley. Link to comment Share on other sites More sharing options...
HartleySan Posted October 3, 2014 Share Posted October 3, 2014 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 More sharing options...
exodia Posted October 3, 2014 Author Share Posted October 3, 2014 thanks again Link to comment Share on other sites More sharing options...
Recommended Posts