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

Yesod.Form.Functions

Contents

Synopsis

Running in MForm monad

newFormIdent :: MForm sub master TextSource

Get a unique identifier.

askParams :: MForm sub master (Maybe Env)Source

Applicative/Monadic conversion

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

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

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)Source

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

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

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

Run a form

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

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)Source

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

Generate a blank form

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

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)Source

Rendering

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

Validation

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

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

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 aSource

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

Allows you to overwrite the error message on parse error.