form

package module
v0.0.0-...-2e51763 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2014 License: MIT Imports: 12 Imported by: 0

README

go-form

Go Form handler based on struct tags and net/url + net/http packages

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LanguagePath string = ""
View Source
var Locale string = "en-US"
View Source
var TemplatePath string = ""

Functions

func GetResource

func GetResource(req *http.Request) (string, string)

func JoinSliceString

func JoinSliceString(class []string) string

func LoadLocale

func LoadLocale(locale string) i18n.TranslateFunc

func ParsePostForm

func ParsePostForm(req *http.Request, s interface{}) error

ParsePostForm parses a net/http Request into url.Values so it can use ParseUrlValues to parse the request

func ParseRequest

func ParseRequest(req *http.Request, s interface{}) error

ParseRequest parses a net/http Request into url.Values so it can use ParseUrlValues to parse the request

func ParseUrlValues

func ParseUrlValues(query url.Values, s interface{}) error

ParseUrlValues parses url.Values into the s interface using the reflect package. It also checks for the form struct tags so they can be used as fieldnames instead of the variable names. It returns the error if parsing failed.

func Render

func Render(res http.ResponseWriter, filename string, render string, data interface{}) []byte

Types

type Element

type Element struct {
	ID          string
	Class       []string
	Type        string
	Name        string
	Label       string
	Value       interface{}
	Placeholder string

	Required   bool
	Autofocus  bool
	NoValidate bool
	Multiple   bool

	TabIndex int64

	Valid bool

	Data       map[string]string
	Options    []*Option
	Validators []Validator
	Errors     []error
}

func NewElement

func NewElement() *Element

type Form

type Form struct {
	ID       string
	Class    []string
	Method   string
	Action   string
	Data     map[string]string
	Valid    bool
	Validate bool
	Locale   string
	Render   string

	Errors   []error
	Success  []string
	Messages []string

	Elements []*Element
}

func CreateFormByJson

func CreateFormByJson(data []byte) *Form

CreateFormByJson creates a NewForm() and fills it using the form json provided

func NewForm

func NewForm() *Form

NewForm creates a default form implementation and fills it with default values where necessery

func (*Form) Check

func (f *Form) Check()

type Option

type Option struct {
	Value    string
	Label    string
	Selected bool
}

func NewOption

func NewOption() *Option

type Validator

type Validator struct {
	Type string
}

func NewValidator

func NewValidator() *Validator

Jump to

Keyboard shortcuts

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