Parse forms (and query strings).
- data GForm s m xml a
- data FormResult a
- = FormMissing
- | FormFailure [String]
- | FormSuccess a
- data Enctype
- = UrlEncoded
- | Multipart
- data FormFieldSettings = FormFieldSettings {}
- newtype Textarea = Textarea {
- unTextarea :: String
- data FieldInfo sub y = FieldInfo {}
- formFailures :: FormResult a -> Maybe [String]
- type Form sub y = GForm sub y (GWidget sub y ())
- type Formlet sub y a = Maybe a -> Form sub y a
- type FormField sub y = GForm sub y [FieldInfo sub y]
- type FormletField sub y a = Maybe a -> FormField sub y a
- type FormInput sub y = GForm sub y [GWidget sub y ()]
- generateForm :: GForm s m xml a -> GHandler s m (xml, Enctype, Html)
- runFormGet :: GForm s m xml a -> GHandler s m (FormResult a, xml, Enctype)
- runFormMonadGet :: GFormMonad s m a -> GHandler s m (a, Enctype)
- runFormPost :: GForm s m xml a -> GHandler s m (FormResult a, xml, Enctype, Html)
- runFormPostNoNonce :: GForm s m xml a -> GHandler s m (FormResult a, xml, Enctype)
- runFormMonadPost :: GFormMonad s m a -> GHandler s m (a, Enctype)
- runFormGet' :: GForm sub y xml a -> GHandler sub y a
- runFormPost' :: GForm sub y xml a -> GHandler sub y a
- fieldsToTable :: FormField sub y a -> Form sub y a
- fieldsToDivs :: FormField sub y a -> Form sub y a
- fieldsToPlain :: FormField sub y a -> Form sub y a
- checkForm :: (a -> FormResult b) -> GForm s m x a -> GForm s m x b
- class ToForm a y where
- class ToFormField a y where
- toFormField :: FormFieldSettings -> FormletField sub y a
- mkToForm :: PersistEntity v => v -> Q [Dec]
- stringField :: (IsForm f, FormType f ~ String) => FormFieldSettings -> Maybe String -> f
- textareaField :: (IsForm f, FormType f ~ Textarea) => FormFieldSettings -> Maybe Textarea -> f
- hiddenField :: (IsForm f, FormType f ~ String) => FormFieldSettings -> Maybe String -> f
- intField :: (Integral (FormType f), IsForm f) => FormFieldSettings -> Maybe (FormType f) -> f
- doubleField :: (IsForm f, FormType f ~ Double) => FormFieldSettings -> Maybe Double -> f
- dayField :: (IsForm f, FormType f ~ Day) => FormFieldSettings -> Maybe Day -> f
- timeField :: (IsForm f, FormType f ~ TimeOfDay) => FormFieldSettings -> Maybe TimeOfDay -> f
- htmlField :: (IsForm f, FormType f ~ Html) => FormFieldSettings -> Maybe Html -> f
- selectField :: (Eq x, IsForm f, FormType f ~ x) => [(x, String)] -> FormFieldSettings -> Maybe x -> f
- boolField :: (IsForm f, FormType f ~ Bool) => FormFieldSettings -> Maybe Bool -> f
- emailField :: (IsForm f, FormType f ~ String) => FormFieldSettings -> Maybe String -> f
- urlField :: (IsForm f, FormType f ~ String) => FormFieldSettings -> Maybe String -> f
- maybeStringField :: (IsForm f, FormType f ~ Maybe String) => FormFieldSettings -> Maybe (Maybe String) -> f
- maybeTextareaField :: FormFieldSettings -> FormletField sub y (Maybe Textarea)
- maybeHiddenField :: (IsForm f, FormType f ~ Maybe String) => FormFieldSettings -> Maybe (Maybe String) -> f
- maybeIntField :: (Integral i, FormType f ~ Maybe i, IsForm f) => FormFieldSettings -> Maybe (FormType f) -> f
- maybeDoubleField :: (IsForm f, FormType f ~ Maybe Double) => FormFieldSettings -> Maybe (Maybe Double) -> f
- maybeDayField :: (IsForm f, FormType f ~ Maybe Day) => FormFieldSettings -> Maybe (Maybe Day) -> f
- maybeTimeField :: (IsForm f, FormType f ~ Maybe TimeOfDay) => FormFieldSettings -> Maybe (Maybe TimeOfDay) -> f
- maybeHtmlField :: (IsForm f, FormType f ~ Maybe Html) => FormFieldSettings -> Maybe (Maybe Html) -> f
- maybeSelectField :: (Eq x, IsForm f, Maybe x ~ FormType f) => [(x, String)] -> FormFieldSettings -> Maybe (FormType f) -> f
- maybeEmailField :: (IsForm f, FormType f ~ Maybe String) => FormFieldSettings -> Maybe (Maybe String) -> f
- maybeUrlField :: (IsForm f, FormType f ~ Maybe String) => FormFieldSettings -> Maybe (Maybe String) -> f
- stringInput :: String -> FormInput sub master String
- intInput :: Integral i => String -> FormInput sub master i
- boolInput :: String -> FormInput sub master Bool
- dayInput :: String -> FormInput sub master Day
- emailInput :: String -> FormInput sub master String
- urlInput :: String -> FormInput sub master String
- maybeStringInput :: String -> FormInput sub master (Maybe String)
- maybeDayInput :: String -> FormInput sub master (Maybe Day)
- maybeIntInput :: Integral i => String -> FormInput sub master (Maybe i)
Data types
A generic form, allowing you to specifying the subsite datatype, master site datatype, a datatype for the form XML and the return type.
data FormResult a Source
A form can produce three different results: there was no data available, the data was invalid, or there was a successful parse.
The Applicative
instance will concatenate the failure messages in two
FormResult
s.
Functor FormResult | |
Applicative FormResult | |
Show a => Show (FormResult a) | |
Monoid m => Monoid (FormResult m) | |
IsForm (GFormMonad s m (FormResult a, FieldInfo s m)) |
The encoding type required by a form. The Show
instance produces values
that can be inserted directly into HTML.
A newtype wrapper around a String
that converts newlines to HTML
br-tags.
Using this as the intermediate XML representation for fields allows us to
write generic field functions and then different functions for producing
actual HTML. See, for example, fieldsToTable
and fieldsToPlain
.
IsForm (GFormMonad s m (FormResult a, FieldInfo s m)) |
Utilities
formFailures :: FormResult a -> Maybe [String]Source
Type synonyms
type FormletField sub y a = Maybe a -> FormField sub y aSource
Unwrapping functions
generateForm :: GForm s m xml a -> GHandler s m (xml, Enctype, Html)Source
Generate a form, feeding it no data. The third element in the result tuple is a nonce hidden field.
runFormGet :: GForm s m xml a -> GHandler s m (FormResult a, xml, Enctype)Source
Run a form against GET parameters.
runFormMonadGet :: GFormMonad s m a -> GHandler s m (a, Enctype)Source
runFormPost :: GForm s m xml a -> GHandler s m (FormResult a, xml, Enctype, Html)Source
Run a form against POST parameters.
This function includes CSRF protection by checking a nonce value. You must therefore embed this nonce in the form as a hidden field; that is the meaning of the fourth element in the tuple.
runFormPostNoNonce :: GForm s m xml a -> GHandler s m (FormResult a, xml, Enctype)Source
Run a form against POST parameters, without CSRF protection.
runFormMonadPost :: GFormMonad s m a -> GHandler s m (a, Enctype)Source
Run a form against POST parameters. Please note that this does not provide CSRF protection.
runFormGet' :: GForm sub y xml a -> GHandler sub y aSource
Run a form against GET parameters, disregarding the resulting HTML and returning an error response on invalid input.
runFormPost' :: GForm sub y xml a -> GHandler sub y aSource
Run a form against POST parameters, disregarding the resulting HTML and returning an error response on invalid input. Note: this does not perform CSRF protection.
Field/form helpers
fieldsToTable :: FormField sub y a -> Form sub y aSource
Display the label, tooltip, input code and errors in a single row of a table.
fieldsToDivs :: FormField sub y a -> Form sub y aSource
Display the label, tooltip, input code and errors in a single div.
fieldsToPlain :: FormField sub y a -> Form sub y aSource
Display only the actual input widget code, without any decoration.
checkForm :: (a -> FormResult b) -> GForm s m x a -> GForm s m x bSource
Add a validation check to a form.
Note that if there is a validation error, this message will not
automatically appear on the form; for that, you need to use checkField
.
Type classes
class ToFormField a y whereSource
toFormField :: FormFieldSettings -> FormletField sub y aSource
ToFormField Bool y | |
ToFormField Double y | |
ToFormField Int y | |
ToFormField Int64 y | |
ToFormField String y | |
ToFormField Html y | |
ToFormField TimeOfDay y | |
ToFormField Day y | |
ToFormField Textarea y | |
ToFormField (Maybe Double) y | |
ToFormField (Maybe Int) y | |
ToFormField (Maybe Int64) y | |
ToFormField (Maybe String) y | |
ToFormField (Maybe Html) y | |
ToFormField (Maybe TimeOfDay) y | |
ToFormField (Maybe Day) y | |
ToFormField (Maybe Textarea) y |
Template Haskell
mkToForm :: PersistEntity v => v -> Q [Dec]Source
Fields
Required
stringField :: (IsForm f, FormType f ~ String) => FormFieldSettings -> Maybe String -> fSource
textareaField :: (IsForm f, FormType f ~ Textarea) => FormFieldSettings -> Maybe Textarea -> fSource
hiddenField :: (IsForm f, FormType f ~ String) => FormFieldSettings -> Maybe String -> fSource
doubleField :: (IsForm f, FormType f ~ Double) => FormFieldSettings -> Maybe Double -> fSource
selectField :: (Eq x, IsForm f, FormType f ~ x) => [(x, String)] -> FormFieldSettings -> Maybe x -> fSource
emailField :: (IsForm f, FormType f ~ String) => FormFieldSettings -> Maybe String -> fSource
Optional
maybeStringField :: (IsForm f, FormType f ~ Maybe String) => FormFieldSettings -> Maybe (Maybe String) -> fSource
maybeTextareaField :: FormFieldSettings -> FormletField sub y (Maybe Textarea)Source
maybeHiddenField :: (IsForm f, FormType f ~ Maybe String) => FormFieldSettings -> Maybe (Maybe String) -> fSource
maybeIntField :: (Integral i, FormType f ~ Maybe i, IsForm f) => FormFieldSettings -> Maybe (FormType f) -> fSource
maybeDoubleField :: (IsForm f, FormType f ~ Maybe Double) => FormFieldSettings -> Maybe (Maybe Double) -> fSource
maybeDayField :: (IsForm f, FormType f ~ Maybe Day) => FormFieldSettings -> Maybe (Maybe Day) -> fSource
maybeTimeField :: (IsForm f, FormType f ~ Maybe TimeOfDay) => FormFieldSettings -> Maybe (Maybe TimeOfDay) -> fSource
maybeHtmlField :: (IsForm f, FormType f ~ Maybe Html) => FormFieldSettings -> Maybe (Maybe Html) -> fSource
maybeSelectField :: (Eq x, IsForm f, Maybe x ~ FormType f) => [(x, String)] -> FormFieldSettings -> Maybe (FormType f) -> fSource
maybeEmailField :: (IsForm f, FormType f ~ Maybe String) => FormFieldSettings -> Maybe (Maybe String) -> fSource
maybeUrlField :: (IsForm f, FormType f ~ Maybe String) => FormFieldSettings -> Maybe (Maybe String) -> fSource
Inputs
Required
stringInput :: String -> FormInput sub master StringSource
emailInput :: String -> FormInput sub master StringSource