I’m using the PRG pattern to avoid multiple form submission. It has, however, a serious drawback — you cannot simply echo
the confirmation message to the user (obviously, the user won’t see the page, he will be redirected to another one).
What are the solutions to this problem? I know two of them, but none of them seems perfect.
http://example.com/?msg=data-saved
. It’s stateless, so I think it’s quite reliable. But it creates problems when user copies the link, bookmarks it, etc.Or maybe there are other ways I don’t know about? Some combination of sessions and URL parameters? I don't know.
What’s the best way in your opinion? Which one has the least drawbacks? What are the pros and cons?
There are several other stack overflow questions that touch on this, though I don't think any summarize the problem so clearly. Here are a few:
Most of the convenient solutions are session-based or have more serious drawbacks (such as embedding the message in the querystring).
If you cannot guarantee that you'll have sessions, another (quite costly) method is to redirect to different views depending on the outcome of the form submission. For example, you might redirect to EditWidgetView
, EditWidgetSaveSuccessfulView
, or EditWidgetSaveErrorView
(or perhaps you just don't redirect on errors). In some languages and frameworks, this is impractical to the point of making you give up on showing confirmation / error messages at all, but in others it may be worth it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With