Page 1 of 1

Page Refresh resubmitting

Posted: Mon Mar 17, 2008 4:25 pm
by LWCARAB
Hello

I have made a questbook style php page, it writes each comment to a textfile which it reads from, this works perfectly.
The problem is that when you press F5 or refresh the page, it re-enters the comment even thouch the textfield and variable has been cleared, I take it the cache is storing the data.
Can someone give me a solution to this problem and be warned I'm a newbie.

Thanks,

Richard

Re: Page Refresh resubmitting

Posted: Mon Mar 17, 2008 4:27 pm
by RobertGonzalez
Any browser that submits a form, when F5'ed, will resubmit the data because of the request method.

To prevent this you could create a form submission id that is checked, and if that ID has already been submitted, redirect away from the form so that the data does not get written a second time.

Better yet, take the user to a landing page after the form submission, then redirect from there or offer links for navigation from there. Try to think of ways of making your users want to click somewhere forward rather than back.

Re: Page Refresh resubmitting

Posted: Mon Mar 17, 2008 4:30 pm
by LWCARAB
Thanks for the reply.
How would I make the form checked?
I thought about forwarding to another page but it's a page that should ideally accept refreshing to view other peoples replies quickly (forum style)

Re: Page Refresh resubmitting

Posted: Mon Mar 17, 2008 4:32 pm
by RobertGonzalez
You don't want a form on a page that needs to be refreshed. If you do, then handle the form processing and the responses refreshing with ajax calls so the page never really needs to be F5'ed.

Re: Page Refresh resubmitting

Posted: Mon Mar 17, 2008 4:35 pm
by LWCARAB
Way behond my capabilities I'm afraid, would coding a page reload after the submit button is pressed clear the "cache" or even put a "thanks for submitting..." page in between work?

Re: Page Refresh resubmitting

Posted: Mon Mar 17, 2008 4:37 pm
by RobertGonzalez
Something else you can do is make the form a page that is linked to from the responses page. After the form is submitted you can land on a 'Thank you' page then meta refresh back to the responses page.