Documentation
¶
Overview ¶
Package frm provides several structs to represent data received from HTML <form> elements via Get or Post HTTP requests.
GetFields must be assigned for this package to be useful.
Index ¶
- Variables
- func GetForms(id uint8, ids ...uint8) (f map[uint8]Form)
- type Field
- func (f *Field) Bytes() (o []byte)
- func (f *Field) Checked() (o bool)
- func (f *Field) Float32() (o float32)
- func (f *Field) Float64() (o float64)
- func (f *Field) Str() (o string)
- func (f *Field) Strs() (o []string)
- func (f *Field) Time() (o time.Time)
- func (f *Field) Uint() (o uint)
- func (f *Field) Uint8() (o uint8)
- func (f *Field) Uint8s() (o []uint8)
- func (f *Field) Uint16() (o uint16)
- func (f *Field) Uint16s() (o []uint16)
- func (f *Field) Uint32() (o uint32)
- func (f *Field) Uint32s() (o []uint32)
- func (f *Field) Uint64() (o uint64)
- func (f *Field) Uint64s() (o []uint64)
- func (f *Field) Uints() (o []uint)
- type Form
- type Option
Constants ¶
This section is empty.
Variables ¶
var GetFields func(uint8) []Field
GetFields defines a function signature to retrieve a form's fields, instead of passing function definitions, pointers, or interfaces between packages. GetFields is relied upon by external packages including session and vl to provide additional session handling and validation functionality.
GetForms requires GetFields to be populated.
An example implementation:
func init() {
const frmNew, frmSave = 0, 1
frm.GetFields = func(id uint8) []frm.Field {
switch id {
case frmNew:
return []frm.Field{{Name: "new", Vl: vl.StrReq}}
case frmSave:
return []frm.Field{{Name: "id", Vl: vl.Regex}, {Name: "save", Vl: vl.StrReq}}
}
return nil
}
}
A more advanced implementation is available for reference in EventBucket/go/forms.go.
BuildIt.ninja can generate the GetFields function when using its Forms code generation feature.
Functions ¶
Types ¶
type Field ¶
type Field struct {
Name, Err, Placeholder string
Options []Option
Max, Min any
MaxLen, MinLen int
Step float32
Regex *regexp.Regexp
Vl func(*Field, ...string) // Function to execute validation rules.
Value any
Required, Disable, Focus bool
}
Field stores attributes for each HTML form field.