The following operations for processing a form in compiled splice ...
bookFormSplice :: C.Splice (Handler App App)
bookFormSplice = formSplice $ do
(view,result) <- DFS.runForm "bookForm" bookForm
case result of Just x -> redirect "/"
Nothing -> return view
Additional application, data, rendering code ...
data Book = Book { title :: T.Text
, description :: T.Text }
bookForm :: Monad m => Form T.Text m Book
bookForm = check "Cannot be blank" notBlank $ Book
<$> "title" .: text (Nothing)
<*> "description" .: text Nothing
where
notBlank (Book t d) = t /= "" && d /= ""
handleNewBook :: Handler App App ()
handleNewBook = cRender "newBook"
routes :: [(ByteString, Handler App App ())]
routes = [ ("/login", with auth handleLoginSubmit)
, ("/logout", with auth handleLogout)
, ("/new_user", with auth handleNewUser)
, ("/newBook", handleNewBook)
, ("", serveDirectory "static")
]
app :: SnapletInit App App
app = makeSnaplet "app" "An snaplet example application." Nothing $ do
h <- nestSnaplet "" heist $ heistInit "templates"
s <- nestSnaplet "sess" sess $
initCookieSessionManager "site_key.txt" "sess" (Just 3600)
a <- nestSnaplet "auth" auth $
initJsonFileAuthManager defAuthSettings sess "users.json"
let config = mempty { hcCompiledSplices = [("bookForm", bookFormSplice)]}
addConfig h config
addRoutes routes
addAuthSplices auth
return $ App h s a
NewBook โโTemplate
New Book Entry:
<br>
<bookForm action="/newBook">
<dfChildErrorList ref="" />
<dfInputText ref="title"/>
<dfInputText ref="description"/>
<dfInputSubmit value="submit"/>
</bookForm>
source
share