Created
January 3, 2011 02:13
-
-
Save softmechanics/763039 to your computer and use it in GitHub Desktop.
Example of Yesod's fileField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE QuasiQuotes | |
, OverloadedStrings | |
, TypeFamilies | |
#-} | |
import Yesod | |
import Control.Applicative | |
data Test = Test | |
data Params = Params | |
{ minNumber :: Int | |
, maxNumber :: Int | |
, singleWord :: String | |
, pluralWord :: String | |
, fileTest :: FileInfo | |
} | |
deriving (Show) | |
paramsFormlet :: Maybe Params -> Form s m Params | |
-- Same as: paramsFormlet :: Formlet s m Params | |
paramsFormlet mparams = fieldsToTable $ Params | |
<$> intField "Minimum number" (fmap minNumber mparams) | |
<*> intField "Maximum number" (fmap maxNumber mparams) | |
<*> stringField "Single word" (fmap singleWord mparams) | |
<*> stringField "Plural word" (fmap pluralWord mparams) | |
<*> fileField "test" | |
getRootR, postRootR :: GHandler Test Test RepHtml | |
getRootR = postRootR | |
postRootR = do | |
(res,w,enc,nonce) <- runFormPost $ paramsFormlet Nothing | |
defaultLayout $ do | |
[$hamlet| | |
%form!enctype=$enc$ | |
$nonce$ | |
$show res$ | |
%table | |
^w^ | |
%tr | |
%td!colspan=2 | |
%input!type=submit | |
|] | |
mkYesod "Test" [$parseRoutes| | |
/ RootR GET POST | |
|] | |
instance Yesod Test where approot _ = "" | |
main = basicHandler 3000 Test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment