I'm trying to use Gorilla's Schema decoder to read in all the post values from my form, but it's not working as expected. I get the schema: invalid path "name" error.
My HTML looks something like this
<form action="/register" method="POST">
<label>Username</label>
<input type="text" name="name" required>
</form>
My logic for processing the registration form in Go looks something this:
err := r.ParseForm()
if err != nil {
log.Println("Form could not be parse")
return
}
var regForm model.RegisterForm // Declare the registration form structure
decoder := schema.NewDecoder() // Creates a schema decoder
decoderr := decoder.Decode(®Form, r.PostForm)
if decoderr != nil {
log.Println(decoderr)
return
}
// More code goes here
My RegisterForm struct looks something like this:
type RegisterForm struct {
Username string `schema: "name"`
Errors map[string]string `schema: "-"`
}
I looked at the docs, but I'm not sure how to match the values of the form properly with my struct.