[Haskell-cafe] Yesod Problem - passing values inside a route

Michael Litchard litchard.michael at gmail.com
Sat May 27 14:32:36 UTC 2017


Below I have an example from the Yesod <https://www.yesodweb.com/book/forms>
book. The form action maps to a route. How do I pass a value to that route.
I know it has something to do with ^ but I can't see to make it work right.

{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE OverloadedStrings
  #-}{-# LANGUAGE QuasiQuotes           #-}{-# LANGUAGE
TemplateHaskell       #-}{-# LANGUAGE TypeFamilies          #-}import
         Control.Applicativeimport           Data.Text
(Text)import           Yesod
data App = App

mkYesod "App" [parseRoutes|/ HomeR GET/input InputR GET|]

instance Yesod App

instance RenderMessage App FormMessage where
    renderMessage _ _ = defaultFormMessage
data Person = Person
    { personName :: Text
    , personAge  :: Int
    }
    deriving Show

getHomeR :: Handler Html
getHomeR = defaultLayout
    [whamlet|
        <form action=@{InputR}>  <--- problem line -- want to do this
<form action=@{InputR ^haskellValue}>
            <p>
                My name is
                <input type=text name=name>
                and I am
                <input type=text name=age>
                years old.
                <input type=submit value="Introduce myself">
    |]

getInputR :: Text -> Handler Html
getInputR label = do
    person <- runInputGet $ Person
                <$> ireq textField label
                <*> ireq intField "age"
    defaultLayout [whamlet|<p>#{show person}|]

main :: IO ()
main = warp 3000 App
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170527/3ec37aaa/attachment.html>


More information about the Haskell-Cafe mailing list