Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

59 lines (44 sloc) 1.274 kB

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
}
Jump to Line
Something went wrong with that request. Please try again.