问题描述
我有一个简单的形式,它有一个名为名字,姓氏,地址和电话号码四个字段。
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.
不过,从成功页面点击浏览器后退按钮表单字段值重新填充表单上。我怎样才能prevent这种情况的发生?
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?
我已经试过这code:
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.
如果你真正想要的是prevent重复提交,与窗体一起发送一个唯一的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).
如果您收到一个重复的,你可以忽略它(并显示相应的消息),或进一步走了一步:检查是否接收到的数据已经提交或者它是否改变previous提交的尝试(即固定一个错字),或创建一个新的记录(也许名字和电话被改变),或提示用户进行选择,或什么的。
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.
这篇关于如何从点击后退按钮后再植prevent表单字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!