reform-0.2.0: reform is an HTML form generation and validation library

Safe Haskell | Safe-Inferred

Text.Reform.Backend

Description

This module contains two classes. `FormInput` is a class which is parameterized over the `input` type used to represent form data in different web frameworks. There should be one instance for each framework, such as Happstack, Snap, WAI, etc.

The `FormError` class is used to map error messages into an application specific error type.

Synopsis

- data CommonFormError input
  - = InputMissing FormId
  - | NoStringFound input
  - | NoFileFound input
  - | MultiFilesFound input
  - | MultiStringsFound input
  - | MissingDefaultValue
- commonFormErrorStr :: (input -> String) -> CommonFormError input -> String
- class FormError e where
  - type ErrorInputType e
  - commonFormError :: CommonFormError (ErrorInputType e) -> e
- class FormInput input where
  - type FileType input
  - getInputString :: (FormError error, ErrorInputType error ~ input) => input -> Either error String
  - getInputStrings :: input -> [String]
  - getInputText :: (FormError error, ErrorInputType error ~ input) => input -> Either error Text
  - getInputTexts :: input -> [Text]
  - getInputFile :: (FormError error, ErrorInputType error ~ input) => input -> Either error (FileType input)

# Documentation

data CommonFormError input Source

an error type used to represent errors that are common to all backends

These errors should only occur if there is a bug in the reform-* packages. Perhaps we should make them an `Exception` so that we can get rid of the `FormError` class.

Constructors

InputMissing FormId |
NoStringFound input |
NoFileFound input |
MultiFilesFound input |
MultiStringsFound input |
MissingDefaultValue |

Instances

Eq input => Eq (CommonFormError input) |
Ord input => Ord (CommonFormError input) |
Show input => Show (CommonFormError input) |

commonFormErrorStr Source

Arguments

:: (input -> String) | show `input` in a format suitable for error messages
-> CommonFormError input | a `CommonFormError`
-> String |

some default error messages for `CommonFormError`

class FormError e where Source

A Class to lift a `CommonFormError` into an application-specific error type

Associated Types

type ErrorInputType e Source

Methods

commonFormError :: CommonFormError (ErrorInputType e) -> eSource

class FormInput input where Source

Class which all backends should implement.

Associated Types

type FileType input Source

`input` is here the type that is used to represent a value uploaded by the client in the request.

Methods

getInputString :: (FormError error, ErrorInputType error ~ input) => input -> Either error String Source

Parse the input into a string. This is used for simple text fields among other things

getInputStrings :: input -> [String]Source

Should be implemented

getInputText :: (FormError error, ErrorInputType error ~ input) => input -> Either error Text Source

Parse the input value into `Text`

getInputTexts :: input -> [Text]Source

Can be overriden for efficiency concerns

getInputFile :: (FormError error, ErrorInputType error ~ input) => input -> Either error (FileType input)Source

Get a file descriptor for an uploaded file