Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle form #44

Closed
guotie opened this issue Jul 8, 2014 · 2 comments
Closed

handle form #44

guotie opened this issue Jul 8, 2014 · 2 comments

Comments

@guotie
Copy link

guotie commented Jul 8, 2014

Is there some middleware or libs?

@elithrar
Copy link
Contributor

elithrar commented Jul 8, 2014

If you want to decode a form into a struct, you can use http://godoc.org/github.com/zenazn/goji/param

i.e.

import (
    "net/http"

    "github.com/zenazn/goji/web"
    "github.com/zenazn/goji/param"
)

type signupForm struct {
    Username string
    Email string
    Address string
    Newsletter bool
}

func FormHandler(c web.C, w http.ResponseWriter, r *http.Request) {
    err := r.ParseForm()
    if err != nil {
        ...
    }

    signupForm := signupForm{}
    err := param.Parse(r.PostForm, &signupForm)
    if err != nil {
        // You can handle the different errors returned by param.Parse here
    }

    // Do with signupForm as you wish!
}

Hope that helps.

@guotie
Copy link
Author

guotie commented Jul 8, 2014

thanks very much

@guotie guotie closed this as completed Jul 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants