PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 13th, 2012, 06:07 PM
knightmetal knightmetal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 knightmetal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 53 sec
Reputation Power: 0
Error message after submitting a form?

Hey guys, I need a little help here.

I don't know how to prevent a user from clicking the back arrow in the browser after a form has been submitted. What I don't want is I don't want the user to submit the same form over and over again by moving back and forth, and in any case, if he/she wanted to do that then it would have to be done from scratch (at least by refreshing the page so that the form is reset).

Any help? suggestions? thanks a lot.

Reply With Quote
  #2  
Old November 13th, 2012, 06:22 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,877 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 5 h 32 m
Reputation Power: 813
Hi,

Simply do a redirect after the submit. See the Post/Redirect/Get pattern.

That's what all online shops do in their checkout process.

Reply With Quote
  #3  
Old November 14th, 2012, 01:02 PM
knightmetal knightmetal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 knightmetal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 53 sec
Reputation Power: 0
Hello Jaques,

Thanks for the suggestion. I understand the concept but I still don't know how to do it in practice in PHP. I probably didn't give enough information about my problem and where I'm at, here's a bit of background:

What I have is a page with an article I wrote. At the bottom of it there's a comment section.

Assuming the user enters the correct details e.g. name, email, comment, the form gets submitted and the user gets redirected to a "thank-you.php" page. On this new page there's a link the user is supposed to click that will take them back to the page where I wrote the article.

When the user clicks the link that takes him back there's no problem, the page gets refreshed the way I want. Problem is when instead of clicking that link the user clicks the back arrow in the browser, basically what happens is that the user is taken exactly to the same line where the comment section is on my page.

Based on your suggestion, I've been reading about PRG pattern and I can't really find a practical example, the examples I've found look complicated, I don't think what I need is such a big deal?

In an article I read they recommend this:

header(‘HTTP/1.1 303 See Other’);
header(‘Location: URL’)

However, that doesn't work for me. What am I doing wrong?

Thanks!

Reply With Quote
  #4  
Old November 14th, 2012, 01:28 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,877 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 5 h 32 m
Reputation Power: 813
What does "not work" mean? Do you get an error message? A header() call must appear before any output.

Reply With Quote
  #5  
Old November 14th, 2012, 01:44 PM
knightmetal knightmetal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 knightmetal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 53 sec
Reputation Power: 0
What I mean is that it seems like the first header is not read at all. My second header IS read though because the user still gets redirected to "thanks.php", but then when I try and click the back arrow the user is sent back to the previous page, which is just what I'm trying to prevent.

These are the two lines I have:

header("HTTP/1.1 303 See Other");
header("Location: thanks.php");

"A header() call must appear before any output."

Sure, I know that. Like I said, my second header works fine, the problem is in the first one. :/

Reply With Quote
  #6  
Old November 14th, 2012, 02:10 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,877 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 5 h 32 m
Reputation Power: 813
The first header has no visible effect, so whatever problems you experience have nothing to do with the header being or not being sent. But you can check the exact response with the developer tools of your browser.

OK, I guess I misunderstood you. So you want to completely remove the page from the browser history? That's a bad idea.

First of all, it's not user-friendly. If I want to view my form input again (for whatever reason) and you don't let me, chances are I'll leave your site and never come back. People expect their browser to behave in a certain way, and if a website breaks this pattern, they'll be annoyed.

Secondly, it's simply uneffective. What prevents me from duplicating the form tab or simply opening the page again? If you want to prevent multi-submits, you need a time limit or check for identical texts.

And last but not least, it's not possible with standard HTML. You need to use JavaScript's location.replace() -- but this can simply be deactivated by anyone.

So I wouldn't do it. Use an intelligent method like a text check.

Reply With Quote
  #7  
Old November 14th, 2012, 02:47 PM
knightmetal knightmetal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 knightmetal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 53 sec
Reputation Power: 0
Thanks Jacques, good points! so I'll break down your comments.

Code:
The first header has no visible effect, so whatever problems you experience have nothing to do with the header being or not being sent. But you can check the exact response with the developer tools of your browser.


Nice, I'll check the developer tools and see if I can find what's going on.

Code:
OK, I guess I misunderstood you. So you want to completely remove the page from the browser history? That's a bad idea.

First of all, it's not user-friendly. If I want to view my form input again (for whatever reason) and you don't let me, chances are I'll leave your site and never come back. People expect their browser to behave in a certain way, and if a website breaks this pattern, they'll be annoyed.


I agree!

I don't necessarily want to remove the page totally from the history but I want to force the user to refresh the page. The problem is that when the user clicks the back arrow, he is taken back exactly to where he left off. He's basically taken to the same line where the comment section is at. Nothing so wrong with that, the problem is that the text he entered is still in the form and if he clicks the Submit button again the form is resubmitted. Now, you said something good in the next paragraph.

Code:
Secondly, it's simply uneffective. What prevents me from duplicating the form tab or simply opening the page again? If you want to prevent multi-submits, you need a time limit or check for identical texts.


I'll try those suggestions, a time limit or check for identical texts, that's probably the way to go about it.

Code:
And last but not least, it's not possible with standard HTML. You need to use JavaScript's location.replace() -- but this can simply be deactivated by anyone.


Sure, I don't want to use JS for any of that stuff as it's not so reliable, it can be simply turned off. That's why I'm trying to do it with PHP but I'm having a hard time with the actual code.

However, the text check sounds good to me, I'll try that and get back to you when I'm done, thanks a lot

Reply With Quote
  #8  
Old November 15th, 2012, 03:31 PM
knightmetal knightmetal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 knightmetal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 53 sec
Reputation Power: 0
Done! the duplicate check did the trick, thanks Jacques

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Error message after submitting a form?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap