See README.md for the consolidated API. This file contains additional detail.
f, err := form.New("content", data) // data implements fmt.Fielder
// → f.GetID() == "content." + data.FormName()
// → f.RenderHTML() renders all matching fields from data.Schema()
// → err != nil if any field has no matching input- Skips fields with
SkipValidationset to true in the input. - Uses
GetSelectedValue()to get current value per input. - Returns the first error encountered.
Synchronizes input values back to the struct pointers provided by data.Pointers().
Supports fmt.FieldText, fmt.FieldInt, fmt.FieldFloat, and fmt.FieldBool.
Validates the provided data using the form's input rules. Satisfies crudp.DataValidator.
type Permitted struct {
Letters bool // A-Z, a-z, Ñ
Tilde bool // Á É Í Ó Ú á é í ó ú
Numbers bool // 0-9
WhiteSpaces bool // space ' '
BreakLine bool // '\n'
Tabulation bool // '\t'
Characters []rune // extra allowed chars e.g. []rune{'@', '.'}
TextNotAllowed []string // blacklisted substrings
Minimum int // minimum length (0 = no limit)
Maximum int // maximum length (0 = no limit)
ExtraValidation func(string) error // custom logic
StartWith *Permitted // rules for first character only
}Error messages from Permitted.Validate():
"minimum N chars"— value shorter than Minimum"maximum N chars"— value longer than Maximum"space not allowed"— space when WhiteSpaces=false"character X not allowed"— disallowed character
Fielder types can optionally implement Namer to provide a custom form name:
type Namer interface {
FormName() string
}