1 reply [Last post]
antibland
antibland's picture
Offline
Leader
Pittsburgh
Last seen: 11 years 31 weeks ago
Pittsburgh
Joined: 2005-01-17
Posts: 603
Points: 0

I wrote a comments script in PHP that I'm having a little problem with. The form submits to itself, does some file operations, and returns to the same page any entries (comments) left by users. This is working fine, but if you leave a comment and then hit refresh, a message comes up warning that "any action the form carried out will be repeated." If you hit 'ok,' the comment will be left again. What I want is for this not to happen. If a user leaves a comment and does a refresh, I want only the results to be returned to the page--nothing extra. To view this behavior, please head over here:

demo

Thanks,

Andrew

Tags:
Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 days 7 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

HTML Form problem

Hi antibland,
This is a problem I have seen many times.
Here one suggested way around it in pseudo code.

  
session start  
if ( session variable has not been set) {  
     check for post data  
     if ( post data) {  
         set session variable  
          display results  
     }else{  // page hasn't been reloaded or submitted 
          display form  
     }  
}else{ //session variable set so form has been refreshed  
     display results   
}
Hope that helps