Closed xpbliss closed 8 years ago
formam needs that you indicate the index of array, but I will solved this problem in a few hours for that you not need indicate the index
Thanks!
the issue is still.
Do you updated it? If the answer is yes... Do you can pass me the code that you is using?
wait for a while
@dashaus Provide an example for slices and <select html input control in the README.md :)
Also a suggestion for contribution, if you want you can join to iris-contrib organisation and I suggest to make a validation package also, more and more iris' users want this and I trust you that you will do your bests
The following is ok! maybe the iris's readForm
should do a fix? @kataras
package main
import (
"fmt"
"github.com/monoculum/formam"
"html/template"
"net/http"
"time"
)
type Visitor struct {
Data []string `formam:"mydata"`
Foundation time.Time `formam:"foundation"`
}
var templ = `<!DOCTYPE html>
<head>
<meta charset="utf-8">
</head>
<body>
<form method="POST" action="/post">
<select multiple="multiple" name="mydata">
<option value='one'>One</option>
<option value='two'>Two</option>
<option value='three'>Three</option>
<option value='four'>Four</option>
</select> <br />
<input type="date" name="foundation" value="1946-05-07"/>
<input type="submit"/>
</form>
</body>
</html>`
func Index(w http.ResponseWriter, r *http.Request) {
t := template.New("Person template")
t, err := t.Parse(templ)
if err != nil {
fmt.Println(err)
}
t.Execute(w, "")
}
func Admin(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method)
visitor := &Visitor{}
r.ParseForm()
if err := formam.Decode(r.Form, visitor); err != nil {
fmt.Println(err)
}
fmt.Println(visitor)
}
func main() {
http.HandleFunc("/", Index)
http.HandleFunc("/post", Admin)
http.ListenAndServe(":8080", nil)
}
@xpbliss Fixed, upgrade iris with go get -u github.com/kataras/iris
also don't forget to do this&Visitor{Data: make([]string, 0)}
@kataras , after `go get -u
, it work well!
For this example, I'm unable to use a multiselect. I have not tried any other element such as checkbox or file. This is a huge show-stopper for me.
<select multiple="multiple" name="mydata[]">
Or
<select multiple="multiple" name="mydata">
Struct: