yesod-form-0.3.4.2: Form handling support for Yesod Web Framework

Yesod.Form.Functions

Contents

- Running in MForm monad
- Applicative/Monadic conversion
- Fields to Forms
- Run a form
- Generate a blank form
- Rendering
- Validation

Synopsis

- newFormIdent :: MForm sub master Text
- askParams :: MForm sub master (Maybe Env)
- askFiles :: MForm sub master (Maybe FileEnv)
- formToAForm :: MForm sub master (FormResult a, FieldView sub master) -> AForm sub master a
- aFormToForm :: AForm sub master a -> MForm sub master (FormResult a, [FieldView sub master] -> [FieldView sub master])
- mreq :: (RenderMessage master msg, RenderMessage master FormMessage) => Field sub master a -> FieldSettings msg -> Maybe a -> MForm sub master (FormResult a, FieldView sub master)
- mopt :: RenderMessage master msg => Field sub master a -> FieldSettings msg -> Maybe (Maybe a) -> MForm sub master (FormResult (Maybe a), FieldView sub master)
- areq :: (RenderMessage master msg, RenderMessage master FormMessage) => Field sub master a -> FieldSettings msg -> Maybe a -> AForm sub master a
- aopt :: RenderMessage master msg => Field sub master a -> FieldSettings msg -> Maybe (Maybe a) -> AForm sub master (Maybe a)
- runFormPost :: RenderMessage master FormMessage => (Html -> MForm sub master (FormResult a, xml)) -> GHandler sub master ((FormResult a, xml), Enctype)
- runFormPostNoNonce :: (Html -> MForm sub master (FormResult a, xml)) -> GHandler sub master ((FormResult a, xml), Enctype)
- runFormGet :: (Html -> MForm sub master a) -> GHandler sub master (a, Enctype)
- generateFormPost :: RenderMessage master FormMessage => (Html -> MForm sub master (FormResult a, xml)) -> GHandler sub master ((FormResult a, xml), Enctype)
- generateFormGet :: (Html -> MForm sub master a) -> GHandler sub master (a, Enctype)
- type FormRender sub master a = AForm sub master a -> Html -> MForm sub master (FormResult a, GWidget sub master ())
- renderTable :: FormRender sub master a
- renderDivs :: FormRender sub master a
- check :: RenderMessage master msg => (a -> Either msg a) -> Field sub master a -> Field sub master a
- checkBool :: RenderMessage master msg => (a -> Bool) -> msg -> Field sub master a -> Field sub master a
- checkM :: RenderMessage master msg => (a -> GGHandler sub master IO (Either msg a)) -> Field sub master a -> Field sub master a
- customErrorMessage :: SomeMessage master -> Field sub master a -> Field sub master a

# Running in MForm monad

newFormIdent :: MForm sub master Text

Get a unique identifier.

askParams :: MForm sub master (Maybe Env)

askFiles :: MForm sub master (Maybe FileEnv)

# Applicative/Monadic conversion

formToAForm :: MForm sub master (FormResult a, FieldView sub master) -> AForm sub master a

aFormToForm :: AForm sub master a -> MForm sub master (FormResult a, [FieldView sub master] -> [FieldView sub master])

# Fields to Forms

mreq :: (RenderMessage master msg, RenderMessage master FormMessage) => Field sub master a -> FieldSettings msg -> Maybe a -> MForm sub master (FormResult a, FieldView sub master)

mopt :: RenderMessage master msg => Field sub master a -> FieldSettings msg -> Maybe (Maybe a) -> MForm sub master (FormResult (Maybe a), FieldView sub master)

areq :: (RenderMessage master msg, RenderMessage master FormMessage) => Field sub master a -> FieldSettings msg -> Maybe a -> AForm sub master a

aopt :: RenderMessage master msg => Field sub master a -> FieldSettings msg -> Maybe (Maybe a) -> AForm sub master (Maybe a)

# Run a form

runFormPost :: RenderMessage master FormMessage => (Html -> MForm sub master (FormResult a, xml)) -> GHandler sub master ((FormResult a, xml), Enctype)

This function is used to both initially render a form and to later extract results from it. Note that, due to CSRF protection and a few other issues, forms submitted via GET and POST are slightly different. As such, be sure to call the relevant function based on how the form will be submitted, not the current request method.

For example, a common case is displaying a form on a GET request and having the form submit to a POST page. In such a case, both the GET and POST handlers should use `runFormPost`.

runFormPostNoNonce :: (Html -> MForm sub master (FormResult a, xml)) -> GHandler sub master ((FormResult a, xml), Enctype)

runFormGet :: (Html -> MForm sub master a) -> GHandler sub master (a, Enctype)

# Generate a blank form

generateFormPost :: RenderMessage master FormMessage => (Html -> MForm sub master (FormResult a, xml)) -> GHandler sub master ((FormResult a, xml), Enctype)

Similar to `runFormPost`, except it always ignore the currently available environment. This is necessary in cases like a wizard UI, where a single page will both receive and incoming form and produce a new, blank form. For general usage, you can stick with `runFormPost`.

generateFormGet :: (Html -> MForm sub master a) -> GHandler sub master (a, Enctype)

# Rendering

type FormRender sub master a = AForm sub master a -> Html -> MForm sub master (FormResult a, GWidget sub master ())

renderTable :: FormRender sub master a

renderDivs :: FormRender sub master a

# Validation

check :: RenderMessage master msg => (a -> Either msg a) -> Field sub master a -> Field sub master a

checkBool :: RenderMessage master msg => (a -> Bool) -> msg -> Field sub master a -> Field sub master a

Return the given error message if the predicate is false.

checkM :: RenderMessage master msg => (a -> GGHandler sub master IO (Either msg a)) -> Field sub master a -> Field sub master a

customErrorMessage :: SomeMessage master -> Field sub master a -> Field sub master a

Allows you to overwrite the error message on parse error.