Ravi, your Pseudo-code is almost perfect, but there is a little bug there.
In the step 3, you have to remove the else statement where you save the token again.
If you do that, this can happen:
1. user hits the load action and save the token
2. user hits the save action and the token is reset
3. user hits back button in the browser
4. user submits again, hits the save action, the token is not valid and it's set again(because of that else)
5. user hits back button in the browser for the second time
6. user submits again the form, hits the save action, and guess what? the token is valid and the data is submitted again.
Regards,
Lucian
PS: Anyway, your example was very helpful for me