Skip to content
HTML forms for Golang
Find file
Pull request Compare This branch is 21 commits behind vmihailenco:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
gaeforms
templates/gforms
README.rst
attrs.go
attrs_test.go
fields.go
fields_test.go
form.go
form_test.go
gforms_test.go
helpers.go
validators.go
widgets.go
widgets_test.go

README.rst

HTML forms for Golang

Installation:

go get github.com/vmihailenco/gforms

Example

Example:

package blog

import (
    "github.com/vmihailenco/gforms"
    "github.com/vmihailenco/gforms/gaeforms"
)

type ArticleForm struct {
    *gforms.BaseForm
    Title    *gforms.StringField
    Text     *gforms.StringField
    IsPublic *gforms.BoolField
    Image    *gaeforms.BlobField
}

func NewArticleForm(article *Article) *ArticleForm {
    title := gforms.NewStringField()
    title.MinLen = 1
    title.MaxLen = 500

    text := gforms.NewTextareaStringField()
    text.MinLen = 1

    isPublic := gforms.NewBoolField()
    isPublic.IsRequired = false
    isPublic.Label = "Is public?"

    image := gaeforms.NewBlobField()

    if article != nil {
        title.SetInitial(article.Title)
        text.SetInitial(article.Text())
        isPublic.SetInitial(article.IsPublic)
    }

    f := &ArticleForm{
        BaseForm: &gforms.BaseForm{},
        Title:    title,
        Text:     text,
        IsPublic: isPublic,
        Image:    image,
    }
    gforms.InitForm(f)

    return f
}
Something went wrong with that request. Please try again.