Hoogle Search
Within LTS Haskell 24.64 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
-
yesod-form Yesod.Form.Functions Creates a hidden field on the form that identifies it. This identification is then used to distinguish between missing and wrong form data when a single handler contains more than one form. For instance, if you have the following code on your handler:
((fooRes, fooWidget), fooEnctype) <- runFormPost fooForm ((barRes, barWidget), barEnctype) <- runFormPost barForm
Then replace it with((fooRes, fooWidget), fooEnctype) <- runFormPost $ identifyForm "foo" fooForm ((barRes, barWidget), barEnctype) <- runFormPost $ identifyForm "bar" barForm
Note that it's your responsibility to ensure that the identification strings are unique (using the same one twice on a single handler will not generate any errors). This allows you to create a variable number of forms and still have them work even if their number or order change between the HTML generation and the form submission. -
yesod-form Yesod.Form.Functions Converts a monadic form MForm into another monadic form WForm.
newFormIdent :: forall (m :: Type -> Type) . Monad m => MForm m Textyesod-form Yesod.Form.Functions Get a unique identifier.
runFormGet :: MonadHandler m => (Markup -> MForm m a) -> m (a, Enctype)yesod-form Yesod.Form.Functions No documentation available.
-
yesod-form Yesod.Form.Functions Run a form for the Post/Redirect/Get pattern, so that invalid input and its validation errors survive a redirect. Use this in both the GET and POST handlers of a route, exactly as you would runFormPost:
- On a POST request this behaves exactly like runFormPost (including CSRF protection). Additionally, on FormFailure the submitted parameters are stashed in the user session so that your handler can simply redirect back to the GET route instead of re-rendering. On FormSuccess any previously stashed parameters for this route are cleared. On FormMissing (another identifyForm-wrapped form on the page was the one submitted) the stash is left untouched.
- On a GET request, if stashed parameters exist for the current path, they are removed from the session and the form is run against them: the fields re-render with the user's input and validation errors, just as a non-redirecting handler would have rendered them. A fresh CSRF token is rendered into the form (the stashed token is discarded, and no token check is performed on a replay). If nothing is stashed, this behaves like generateFormPost (the result is FormMissing).
getRegisterR :: Handler Markup getRegisterR = do ((_res, widget), enctype) <- runFormPRG personForm defaultLayout [whamlet| <form method=post action=@{RegisterR} enctype=#{enctype}> ^{widget} |] postRegisterR :: Handler Markup postRegisterR = do ((res, _widget), _enctype) <- runFormPRG personForm case res of FormSuccess person -> do -- insert into the database, etc. setMessage "Registered!" redirect RegisterR _ -> redirect RegisterRNotes and caveats:- The stash is keyed by request path, so the GET and POST handlers must share a route (the common Yesod pattern). Form pages on different routes do not interfere with each other; two tabs on the same path share one stash (the last failed submission wins).
- Multiple forms on one page work when wrapped with identifyForm: on replay, only the form that was actually submitted re-renders with values and errors; the others return FormMissing and render blank. (The stash is popped once per request and shared between calls via the per-request cache, so every form in the handler sees it.)
- Uploaded files are not stashed; file fields re-render empty after the redirect.
- The stashed parameters live in the user session. With the default client-session backend the whole session must fit in a cookie (roughly 4KB), so this is unsuitable for very large forms. If the stash fails to decode, it is discarded and a blank form is generated.
- If the application has no session backend, stashing is a no-op and this degrades to runFormPost/generateFormPost semantics (input will not survive the redirect).
- If your POST handler re-renders on failure instead of redirecting, do not use this function: the stash would be consumed by an unrelated later GET of the same path.
- On a replay the form may even produce FormSuccess (e.g. a checkM validation whose outcome depends on external state); the result is returned as-is. GET handlers normally use only the widget.
- A HEAD request reads the stash without consuming it, so that middleware such as autoHead does not eat the replay meant for the subsequent GET.
-
yesod-form Yesod.Form.Functions 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.
runFormPostNoToken :: MonadHandler m => (Markup -> MForm m a) -> m (a, Enctype)yesod-form Yesod.Form.Functions No documentation available.
wFormToAForm :: forall (m :: Type -> Type) a . MonadHandler m => WForm m (FormResult a) -> AForm m ayesod-form Yesod.Form.Functions Converts a monadic form WForm into an applicative form AForm.
-
yesod-form Yesod.Form.Functions Converts a monadic form WForm into another monadic form MForm.
chineseFormMessage :: FormMessage -> Textyesod-form Yesod.Form.I18n.Chinese No documentation available.