runFormPostTable and runFormPostDivs
This commit is contained in:
parent
f80cfab5d7
commit
0b5b132fa3
@ -29,6 +29,9 @@ module Yesod.Form
|
||||
, runFormMonadPost
|
||||
, runFormGet'
|
||||
, runFormPost'
|
||||
-- ** High-level form post unwrappers
|
||||
, runFormPostTable
|
||||
, runFormPostDivs
|
||||
-- * Field/form helpers
|
||||
, fieldsToTable
|
||||
, fieldsToDivs
|
||||
@ -45,6 +48,7 @@ import Yesod.Form.Core
|
||||
import Yesod.Form.Fields
|
||||
import Yesod.Form.Class
|
||||
import Yesod.Form.Profiles (Textarea (..))
|
||||
import Yesod.Widget (GWidget)
|
||||
|
||||
import Text.Hamlet
|
||||
import Yesod.Request
|
||||
@ -144,6 +148,41 @@ runFormPost' f = do
|
||||
x <- runFormGeneric pp files f
|
||||
helper x
|
||||
|
||||
-- | Create a table-styled form.
|
||||
--
|
||||
-- This function wraps around 'runFormPost' and 'fieldsToTable', taking care of
|
||||
-- some of the boiler-plate in creating forms. In particular, is automatically
|
||||
-- creates the form element, sets the method, action and enctype attributes,
|
||||
-- adds the CSRF-protection nonce hidden field and inserts a submit button.
|
||||
runFormPostTable :: Route m -> String -> FormField s m a
|
||||
-> GHandler s m (FormResult a, GWidget s m ())
|
||||
runFormPostTable dest inputLabel form = do
|
||||
(res, widget, enctype, nonce) <- runFormPost $ fieldsToTable form
|
||||
let widget' = [$hamlet|
|
||||
%form!method=post!action=@dest@!enctype=$enctype$
|
||||
%table
|
||||
^widget^
|
||||
%tr
|
||||
%td!colspan=2
|
||||
$nonce$
|
||||
%input!type=submit!value=$inputLabel$
|
||||
|]
|
||||
return (res, widget')
|
||||
|
||||
-- | Same as 'runFormPostTable', but uses 'fieldsToDivs' for styling.
|
||||
runFormPostDivs :: Route m -> String -> FormField s m a
|
||||
-> GHandler s m (FormResult a, GWidget s m ())
|
||||
runFormPostDivs dest inputLabel form = do
|
||||
(res, widget, enctype, nonce) <- runFormPost $ fieldsToDivs form
|
||||
let widget' = [$hamlet|
|
||||
%form!method=post!action=@dest@!enctype=$enctype$
|
||||
^widget^
|
||||
%div
|
||||
$nonce$
|
||||
%input!type=submit!value=$inputLabel$
|
||||
|]
|
||||
return (res, widget')
|
||||
|
||||
-- | Run a form against GET parameters, disregarding the resulting HTML and
|
||||
-- returning an error response on invalid input.
|
||||
runFormGet' :: GForm sub y xml a -> GHandler sub y a
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: yesod
|
||||
version: 0.6.1.3
|
||||
version: 0.6.2
|
||||
license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Michael Snoyman <michael@snoyman.com>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user