frm

package module
v0.0.0-...-4b724f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 2 Imported by: 3

README

forms

Go Reference Go Report Card

Go form structure.

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

Constants

This section is empty.

Variables

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

func GetForms

func GetForms(id uint8, ids ...uint8) (f map[uint8]Form)

GetForms retrieves forms by their ids. The duplicate ids parameter is to ensure at least one uint8 is passed to the function without adding additional checks (same as Go's built-in exec.Command()).

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.

func (*Field) Bytes

func (f *Field) Bytes() (o []byte)

Bytes returns f.Value as a byte slice.

func (*Field) Checked

func (f *Field) Checked() (o bool)

Checked returns f.Value as a boolean.

func (*Field) Float32

func (f *Field) Float32() (o float32)

Float32 returns f.Value as a float32.

func (*Field) Float64

func (f *Field) Float64() (o float64)

Float64 returns f.Value as a float64.

func (*Field) Str

func (f *Field) Str() (o string)

Str returns f.Value as a string.

func (*Field) Strs

func (f *Field) Strs() (o []string)

Strs returns f.Value as a string slice.

func (*Field) Time

func (f *Field) Time() (o time.Time)

Time returns f.Value as a datetime.

func (*Field) Uint

func (f *Field) Uint() (o uint)

Uint returns f.Value as an unsigned integer.

func (*Field) Uint8

func (f *Field) Uint8() (o uint8)

Uint8 returns f.Value as an unsigned integer.

func (*Field) Uint8s

func (f *Field) Uint8s() (o []uint8)

Uint8s returns f.Value as an unsigned integer slice.

func (*Field) Uint16

func (f *Field) Uint16() (o uint16)

Uint16 returns f.Value as an unsigned integer.

func (*Field) Uint16s

func (f *Field) Uint16s() (o []uint16)

Uint16s returns f.Value as an unsigned integer slice.

func (*Field) Uint32

func (f *Field) Uint32() (o uint32)

Uint32 returns f.Value as an unsigned integer.

func (*Field) Uint32s

func (f *Field) Uint32s() (o []uint32)

Uint32s returns f.Value as an unsigned integer slice.

func (*Field) Uint64

func (f *Field) Uint64() (o uint64)

Uint64 returns f.Value as an unsigned integer.

func (*Field) Uint64s

func (f *Field) Uint64s() (o []uint64)

Uint64s returns f.Value as an unsigned integer slice.

func (*Field) Uints

func (f *Field) Uints() (o []uint)

Uints returns f.Value as an unsigned integer slice.

type Form

type Form struct {
	Action uint8
	Fields []Field
	Err    error
}

Form stores details about an HTML form.

type Option

type Option struct {
	Label, Value string
	Selected     bool
}

Option represents attributes for an option within a select box, list box or data list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL