Created
March 21, 2016 09:44
-
-
Save ysqi/62367e12d0972c6cf696 to your computer and use it in GitHub Desktop.
beego get multipevalue from post form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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