Yesod 中的确认对话框
在 Yesod 中创建确认对话框的最简单方法是什么?在某些情况下,当发布表单时,我想在执行操作之前要求确认。我想象这是通过向用户发送一个单独的确认页面,然后在按下“是”按钮时处理发布的数据来实现的。
我认为这应该是可能的,使用像 setUltDestReferer 这样的函数。问题是,在 Yesod 中最简单/最典型的方法是什么?理想情况下,它应该归结为处理程序中的单个函数调用,就像 requireAuth 那样。
What is the simplest way to make a confirmation dialog in Yesod? In some cases, when a form is posted, I want to ask for confirmation before carrying out the action. I imagine this working by sending the user a separate confirmation page, and then processing the posted data if the 'Yes' button is pressed.
I think this should be possible, using functions like setUltDestReferer. The question is, what is the easiest/most typical way to do it in Yesod? Ideally it should boil down to a single function call in the handler, like requireAuth does.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解正确,您需要一些能够
这就立即提出了如何携带原始表单数据的问题。有多种方法可以解决此问题,例如将其存储在会话中或将其 URL 编码包含在“是”链接中。
后一种方法有效,但可能有点混乱。当用户点击后退按钮、在新选项卡中打开链接等时,前者可能会导致问题。这来自于HTTP的无状态设计。
可能会更清晰
If I understood this right, you want something that will
This immediately raises the question of how the original form data should be carried along. There are ways of solving this, e.g. by storing it in the session or by including it URL encoded in the "Yes" link.
The latter approach works, but can be a bit messy. The former can cause problems when users hit the back button, open links in new tabs and so on. This comes from the stateless design of HTTP.
Instead, it might be cleaner to create a new AJAX handler and add some JavaScript that
我建议您采用@hammar 的方法,我认为这是最好的。如果由于某种原因无法选择 AJAX,您可以考虑在包含从第一页提交的表单数据的确认页面上放置一个隐藏表单。使用
runRequestBody
。I recommend you go with @hammar's approach, I think it's the best. If for some reason AJAX isn't an option, you can consider putting a hidden form on the confirmation page containing the form data submitted from the first page. This should be fairly trivial using
runRequestBody
.