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

Safe HaskellSafe-Infered

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

renderBootstrap :: FormRender sub master aSource

Render a form using Bootstrap-friendly shamlet syntax.

Sample Hamlet:

        <form method=post action=@{ActionR} enctype=#{formEnctype}>
          <fieldset>
            <legend>_{MsgLegend}
            $case result
              $of FormFailure reasons
                $forall reason <- reasons
                  <div .alert-message .error>#{reason}
              $of _
            ^{formWidget}
            <div .actions>
              <input .btn .primary type=submit value=_{MsgSubmit}>

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 -> GHandler sub master (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.

Utilities

fieldSettingsLabel :: msg -> FieldSettings msgSource

Generate a FieldSettings from the given label.

aformM :: GHandler sub master a -> AForm sub master aSource

Generate an AForm that gets its value from the given action.