form

package
v0.0.0-...-a4815f4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2013 License: MIT Imports: 4 Imported by: 0

README

form

POST form parser/handler for Martini.

API Reference

Description

form provides a convenient way to map http POST forms to struct fields. form will conveniently inject the given struct as a service for subsequent handlers.

Usage

package main

import (
   "github.com/codegangsta/martini"
   "github.com/codegangsta/martini-contrib/form"
 )

type BlogPost struct{
   Title string `form:"title,required"`
   Content string `form:"content"`
}

func main() {
  m := martini.Classic()

  m.Post("/blog", form.Form(&BlogPost{}), func(blogpost *BlogPost) string {
    return blogpost.Title
  })

  m.Run()
}

Authors

Documentation

Overview

Package form implements a handler for post and get forms.

For a full guide visit http://github.com/codegangsta/martini

package main

import (
   "github.com/codegangsta/martini"
   "github.com/codegangsta/martini-contrib/form"
 )

type BlogPost struct{
   Title string `form:"title,required"`
   Content string `form:"content"`
}

func main() {
  m := martini.Classic()

  m.Get("/", form.Form(&BlogPost{}), func(blogpost *BlogPost) string {
    return blogpost.Title
  })

  m.Run()
}

Index

Constants

View Source
const (
	// Error for fields which are marked as required but weren't present in the form.
	RequireError string = "RequireError"
)

Variables

This section is empty.

Functions

func Form

func Form(formstruct interface{}) martini.Handler

Create a new formhandler. Errors are available via form.Errors-Service.

Types

type Errors

type Errors map[string]string

Available errors. Use len() to check if any errors occured.

Jump to

Keyboard shortcuts

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