From a5898ea6f8a11e2429dca6d4ecd6c8b667964021 Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Sat, 8 Jul 2017 20:22:52 +0200 Subject: [PATCH] docs(readme): add binding html checkbox example, close #129 --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index eda1dd702a..a593a59f44 100644 --- a/README.md +++ b/README.md @@ -481,6 +481,52 @@ func startPage(c *gin.Context) { } ``` +### Bind HTML checkboxes + +See the [detail information](https://github.com/gin-gonic/gin/issues/129#issuecomment-124260092) + +main.go + +```go +... + +type myForm struct { + Colors []string `form:"colors[]"` +} + +... + +func formHandler(c *gin.Context) { + var fakeForm myForm + c.Bind(&fakeForm) + c.JSON(200, gin.H{"color": fakeForm.Colors}) +} + +... + +``` + +form.html + +```html +
+

Check some colors

+ + + + + + + +
+``` + +result: + +``` +{"color":["red","green","blue"]} +``` + ### Multipart/Urlencoded binding ```go