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

Yesod.Form.Core

Contents

Description

Users of the forms library should not need to use this module in general. It is intended only for writing custom forms and form fields.

Synopsis

Documentation

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.

newtype GForm s m 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 :: FormInner s m (FormResult a, xml, Enctype)
 

Instances

Monoid xml => Functor (GForm sub url xml) 
Monoid xml => Applicative (GForm sub url xml) 
RunForm (GForm s m xml a) 

newFormIdent :: Monad m => StateT Ints m StringSource

Get a unique identifier.

type Env = [(String, String)]Source

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 Ints Source

Constructors

IntCons Int Ints 
IntSingle Int 

Instances

requiredFieldHelper :: IsForm f => FieldProfile (FormSub f) (FormMaster f) (FormType f) -> FormFieldSettings -> Maybe (FormType f) -> fSource

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

optionalFieldHelper :: (IsForm f, Maybe b ~ FormType f) => FieldProfile (FormSub f) (FormMaster f) b -> FormFieldSettings -> Maybe (Maybe b) -> fSource

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

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

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

Convert the XML in a GForm.

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.

checkField :: (a -> Either String b) -> FormField s m a -> FormField s m bSource

Add a validation check to a FormField.

Unlike checkForm, the validation error will appear in the generated HTML of the form.

class IsForm f whereSource

Associated Types

type FormSub f Source

type FormMaster f Source

type FormType f Source

Methods

toForm :: FormInner (FormSub f) (FormMaster f) (FormResult (FormType f), FieldInfo (FormSub f) (FormMaster f), Enctype) -> fSource

Instances

class RunForm f whereSource

Associated Types

type RunFormSub f Source

type RunFormMaster f Source

type RunFormType f Source

Instances

RunForm (GFormMonad s m a) 
RunForm (GForm s m xml a) 

type GFormMonad s m a = WriterT Enctype (FormInner s m) aSource

Data types

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 

Instances

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 

Fields

fpParse :: String -> Either String a
 
fpRender :: a -> String
 
fpWidget :: String -> String -> String -> Bool -> GWidget sub y ()

ID, name, value, required

Type synonyms

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