显示消息时 Kohana 不重新提交
在涉及表单操作的 kohana 控制器中,我用来声明一条 vire 消息,例如:
$this->view->message = __('mESSAGE HERE');
让用户知道表单已成功提交。
以我的形式:
<? if(isset($message)):?>
<p class="message"><?= $message; ?></p>
<form id=.........
因此,在提交表单后,如果成功,则会显示一条消息。我的问题是:
如果此人刷新页面,则重新提交表单:((可以以某种方式避免这种情况吗?(最终不使用重定向,而只是使用 javascript/jquery)?
谢谢!
in kohana controllers that involve form manipulations, i use to declare a vire message like:
$this->view->message = __('mESSAGE HERE');
for the user to know that the form has been successfully submited.
in the form i have:
<? if(isset($message)):?>
<p class="message"><?= $message; ?></p>
<form id=.........
so after some submit the form, if it was a succes, it is displayed a message. my problem is:
if this person refreshes the page, the form is resubmited :(( can this be avoided somehow? (eventually without using redirect, but just javascript/jquery)?
thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用随机字符串创建隐藏字段(仅当 POST 为空时!)。相同的字符串(令牌)保存在会话中。所以,提交成功后需要清除会话密钥。此外,此方法有助于避免 跨站请求伪造
无论如何,重定向是防止用户收到有关重新发送请求数据的混乱消息的最佳方法
You can create a hidden field with a random string (only when POST is empty!). The same string (token) saves in session. So, after succesfully submit you need to clear session key. Also, this method helps to avoid cross-site request forgeries
Anyway, redirect is the best way to prevent the user from the confusing messages about re-sending the request data