2
比方說,我們有這樣的事情:如何編寫檢查兩個文件是否相同的Yesod表單?
myForm :: Form (Text, Text)
myForm = renderBootstrap3 BootstrapBasicForm $ (,)
<$> areq passwordField (bfs ("Password" :: Text)) Nothing
<*> areq passwordField (bfs ("Repeat password" :: Text)) Nothing
是否有可能來檢查這兩個領域是否相同?驗證是 描述here, check
似乎不夠強大,執行這種檢查。也許 checkM
可能有些用處?
如果不能使用內置的Yesod工具, 最好的解決方法是什麼?我能想到的:
postSomethingR :: Handler Html
postSomethingR = do
((result, form), enctype) <- runFormPost myForm
case result of
FormSuccess (password0, password1) -> do
if password0 == password1
then
-- do your thing
else
-- serve the form again and perhaps set message telling that
-- passwords don't match?