开发者

Confirmation dialogs in Yesod

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 e开发者_如何学编程asiest/most typical way to do it in Yesod? Ideally it should boil down to a single function call in the handler, like requireAuth does.


If I understood this right, you want something that will

  1. Render some confirmation page and abort further processing of the request.
  2. Have the "Yes" button link back to this handler and set a flag.
  3. If the flag is set, do nothing and continue with the request instead.

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

  1. Calls the handler to check if confirmation is needed.
  2. Shows the confirmation if that was the case.
  3. If the user clicked "Yes", proceeds with submitting the form as you normally would.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜