On the tmpl document page, there is a form:

<form id="createform" name="createform" action="/clickCreateRashod" method="post"> <div class="col-lg-6"> <input id="first" name="first" value="Name1"> <input id="first" name="first" value="Name2"> <input id="first" name="first" value="Name3"> <input id="two" name="two" value="5"> <button type="submit" class="btn" >Add</button> </form> 

So here's how I get the values ​​of all three "first" functions in gin: Handler function:

 r.POST("/clickCreateRashod", clickCreateRashodHandle) func clickCreateRashodHandle(c *gin.Context) { //Тут я писал уже кучу всего, как сделать правильно? } 

For a single c.PostForm ("first") value, how to read everything into an array? You can also give an example from the standard library.

  • three elements with the same id? interesting. - KoVadim
  • For reference, you can remove them, go only name is interesting - Oma

1 answer 1

I do not see such methods in gin, but in general this is done via http.(*Request).ParseForm and reading directly from http.Request.Form by key:

 r := c.Request err := r.ParseForm() if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } fmt.Println(r.Form["first"])