form

package
v0.0.0-...-dc37515 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Delegate

type Delegate interface {
	GetAccessCheck(r *http.Request) page.AccessChecker
	LoadData(r *http.Request) (interface{}, error)
	Submit(w http.ResponseWriter, r *http.Request, v interface{}) FormSubmitResult
}

Delegate is a helper type that contains the form presentation and logic.

type ErrInvalidFormContentType

type ErrInvalidFormContentType string

ErrInvalidFormContentType is an error that happens when a form submission happens with an incorrect content type.

func (ErrInvalidFormContentType) Error

type Form

type Form struct {
	// contains filtered or unexported fields
}

Form has handlers for a standard HTML form.

func NewForm

func NewForm(store keyvalue.Store, title string, page *template.Template, delegate Delegate) *Form

NewForm creates a new instance of Form.

The key-value store will hold the form tokens. The page template is the surrounding page which will embed the form.

func (*Form) Page

func (f *Form) Page(w http.ResponseWriter, r *http.Request)

Page is the main page that shows the form.

func (*Form) Pages

func (f *Form) Pages(path string, middlewares ...negroni.Handler) []server.Route

func (*Form) Submit

func (f *Form) Submit(w http.ResponseWriter, r *http.Request)

Submit is the endpoint that handles the form submission.

type FormPageData

type FormPageData struct {
	Errors    []string
	FormID    string
	FormToken string
	Data      interface{}
}

FormPageData represents the form state.

The Data attribute has the custom data that is either posted or loaded.

func (*FormPageData) CSRFToken

func (f *FormPageData) CSRFToken() template.HTML

func (*FormPageData) ErrorMessages

func (f *FormPageData) ErrorMessages() template.HTML

type FormSubmitResult

type FormSubmitResult interface {
	// Do is the action, returning whether the form is needed to be rebuilt
	// or not.
	Do(w http.ResponseWriter, r *http.Request, fd *FormPageData) bool
}

FormSubmitResult represents what should happen after a form submit.

func Error

func Error(message string, err error) FormSubmitResult

Error tells a form that an error happened during the form submission.

func Redirect

func Redirect(path string) FormSubmitResult

Redirect tells a form to redirect after submit.

type Validator

type Validator interface {
	Delegate
	Validate(r *http.Request, v interface{}) []string
}

Validator is a form delegate that validates the form data.

Jump to

Keyboard shortcuts

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