单击后退按钮后如何防止表单字段重新填充? [英] How to prevent form fields from repopulating after clicking the back button?
问题描述
我有一个简单的表单,它有四个字段,分别是名字、姓氏、地址和电话号码.
I have a simple form which has four fields named firstName, lastName, address and phone number.
在用户填写此表单并单击提交按钮后,如果一切顺利,我会将用户重定向到成功页面.
After a user fills this form and clicks the submit button, if everything goes fine, I am redirecting that user to a success page.
但是在成功页面上单击浏览器后退按钮时,表单字段值会重新填充到表单上.我怎样才能防止这种情况发生?
But on clicking the browser back button from the success page the form field values are repopulating on the form. How can I prevent this from happening?
我已经尝试过这个代码:
I have already tried this code:
<cfheader name="cache-control" value="no-cache, no-store, must-revalidate">
<cfheader name="pragma" value="no-cache">
<cfheader name="expires" value="#getHttpTimeString(now()-1)#">
但它不起作用.
推荐答案
重新填充表单域是一件好事,不要试图破坏它.
Repopulating form fields is a good thing, stop trying to break it.
如果您真正想要的是防止重复提交,请将唯一 ID(例如 UUID)与表单一起发送并跟踪您最近收到的那些(跟踪多少取决于您的应用程序).
If what you actually want is to prevent duplicate submissions, send a unique id (e.g. UUID) along with the form and keep track of the ones you've received recently (how many to keep track of depends on your application).
如果您收到重复的数据,您可以忽略它(并显示适当的消息),或者更进一步:检查接收到的数据是否已经提交,或者是否试图更改之前的提交(即修正错字)),或创建新记录(可能更改了名字和电话),或提示用户选择,或其他.
If you receive a duplicate you can either ignore it (and display appropriate message), or go a step further: check whether the received data has already been submitted or whether it's an attempt to change the previous submission (i.e. fixing a typo), or to create a new record (maybe firstname and phone were changed), or prompt the user to choose, or whatever.
这篇关于单击后退按钮后如何防止表单字段重新填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!