Prevent comment form re-submission

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-04-28T16:34:10Z Indexed on 2010/04/28 16:43 UTC
Read the original article Hit count: 311

Filed under:
|
|
|

I'm got a comment form for an article and i'd to prevent re-submission. I notice that Worpdress handles this very well (going back doesn't cause the browser to request a form re-submission), but I can't figure out how they do it, even though our methods are very similar.

My Script

User visits mydomain.com/article/1/article_title.html

Fills in a form which posts to mydomain.com/addnewcomment/1.html

I then do a 302 redirect back to mydomain.com/article/1/article_title.html

Now if I press back from this position it doesn't request a redirect. However, if I go to another page e.g. mydomain.com/tag/1/my_tag.html and press back it does resubmit the form.

Obviously I want to prevent this.

What Wordpress does

User visits mydomain.com/?p=1 Fills in a form which posts to mydomain.com/wp-comments-post.php This then does a 302 redirect back to mydomain.com/?p=1

Pressing back or visiting another page and pressing back doesn't cause a re-submission.

I've had a look through the WP code but I can't see how they manage this. Obviously it's something i'd like to achieve.

Does anyone have any thoughts on where I may be going wrong?

(I'm only using Wordpress as an example to prove that it's possible, obviously i'm not trying to exactly duplicate WP, that would be pointless)

© Stack Overflow or respective owner

Related posts about form

Related posts about html