yesod-0.4.0.2: Creation of type-safe, RESTful web applications.

Yesod.Form

Contents

Description

Parse forms (and query strings).

Synopsis

Data types

newtype GForm sub y xml a Source

A generic form, allowing you to specifying the subsite datatype, master site datatype, a datatype for the form XML and the return type.

Constructors

GForm 

Fields

deform :: Env -> FileEnv -> StateT Int (GHandler sub y) (FormResult a, xml, Enctype)
 

Instances

Monoid xml => Functor (GForm sub url xml) 
Monoid xml => Applicative (GForm sub url xml) 

type Form sub y = GForm sub y (GWidget sub y ())Source

type Formlet sub y a = Maybe a -> Form sub y aSource

type FormField sub y = GForm sub y [FieldInfo sub y]Source

type FormletField sub y a = Maybe a -> FormField sub y aSource

type FormInput sub y = GForm sub y [GWidget sub y ()]Source

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 FormResults.

data Enctype Source

The encoding type required by a form. The Show instance produces values that can be inserted directly into HTML.

Constructors

UrlEncoded 
Multipart 

data FieldInfo sub y Source

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.

Constructors

FieldInfo 

Newtype wrappers

newtype JqueryDay Source

A newtype wrapper around Day, using jQuery UI date picker for the ToFormField instance.

Constructors

JqueryDay 

Fields

unJqueryDay :: Day
 

Unwrapping functions

runFormGet :: GForm sub y xml a -> GHandler sub y (FormResult a, xml, Enctype)Source

Run a form against GET parameters.

runFormPost :: GForm sub y xml a -> GHandler sub y (FormResult a, xml, Enctype)Source

Run a form against POST parameters.

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.

Type classes

class ToForm a whereSource

Methods

toForm :: Maybe a -> Form sub y aSource

Field/form helpers

requiredFieldHelper :: FieldProfile sub y a -> Maybe a -> FormField sub y aSource

Create a required field (ie, one that cannot be blank) from a FieldProfile.

optionalFieldHelper :: FieldProfile sub y a -> Maybe (Maybe a) -> FormField sub y (Maybe a)Source

Create an optional field (ie, one that can be blank) from a FieldProfile.

mapFormXml :: (xml1 -> xml2) -> GForm s y xml1 a -> GForm s y xml2 aSource

Convert the XML in a GForm.

newFormIdent :: Monad m => StateT Int m StringSource

Get a unique identifier.

fieldsToTable :: [FieldInfo sub y] -> GWidget sub y ()Source

Display the label, tooltip, input code and errors in a single row of a table.

fieldsToPlain :: [FieldInfo sub y] -> GWidget sub y ()Source

Display only the actual input widget code, without any decoration.

fieldsToInput :: [FieldInfo sub y] -> [GWidget sub y ()]Source

Field profiles

data FieldProfile sub y a Source

A generic definition of a form field that can be used for generating both required and optional fields. See 'requiredFieldHelper and optionalFieldHelper.

Constructors

FieldProfile 

Pre-built fields

selectField :: Eq x => [(x, String)] -> Html () -> Html () -> Maybe x -> FormField sub master xSource

maybeSelectField :: Eq x => [(x, String)] -> Html () -> Html () -> Maybe x -> FormField sub master (Maybe x)Source

Pre-built inputs

Template Haskell

share2 :: Monad m => (a -> m [b]) -> (a -> m [b]) -> a -> m [b]Source

This function allows two different monadic functions to share the same input and have their results concatenated. This is particularly useful for allowing mkToForm to share its input with mkPersist.

mkToForm :: [EntityDef] -> Q [Dec]Source

Create ToForm instances for the entities given. In addition to regular EntityDef attributes understood by persistent, it also understands label= and tooltip=.