Skip to content

Instantly share code, notes, and snippets.

@ysqi
Created March 21, 2016 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysqi/62367e12d0972c6cf696 to your computer and use it in GitHub Desktop.
Save ysqi/62367e12d0972c6cf696 to your computer and use it in GitHub Desktop.
beego get multipevalue from post form
package main
import (
"fmt"
"text/template"
"github.com/astaxie/beego"
)
func main() {
beego.Run()
}
func init() {
beego.Router("/", &MainController{})
}
type MainController struct {
beego.Controller
}
func (c *MainController) Get() {
tmpl := template.Must(template.New("Study").Parse(html))
tmpl.Execute(c.Ctx.ResponseWriter, nil)
}
func (c *MainController) Post() {
arr := c.GetStrings("category")
c.Ctx.WriteString(fmt.Sprintf("Your selected:%s", arr))
}
const html = `
<!DOCTYPE html>
<html>
<head>
<title>Beego</title>
</head>
<body>
<form action="/" method="POST" >
<select multiple name="category" id="category">
<option value="1" >category 1</option>
<option value="2" >category 2</option>
<option value="3" >category 3</option>
</select>
<button type="submit">Submit</button>
</form>
</body>
</html>
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment