From c7157f1c92a7e793ad82c47637c79a20d3ff3b1c Mon Sep 17 00:00:00 2001
From: "Gerasimos (Makis) Maropoulos" <kataras2006@hotmail.com>
Date: Tue, 1 Sep 2020 11:39:57 +0300
Subject: [PATCH] add bind checkboxes example

---
 _examples/README.md                           |  1 +
 .../request-body/read-form/checkboxes/main.go | 32 +++++++++++++++++++
 .../read-form/checkboxes/templates/form.html  | 22 +++++++++++++
 go.mod                                        |  2 +-
 4 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 _examples/request-body/read-form/checkboxes/main.go
 create mode 100644 _examples/request-body/read-form/checkboxes/templates/form.html

diff --git a/_examples/README.md b/_examples/README.md
index 7bb18b94..44d24cac 100644
--- a/_examples/README.md
+++ b/_examples/README.md
@@ -137,6 +137,7 @@
     * [Bind MsgPack](request-body/read-msgpack/main.go)
     * [Bind YAML](request-body/read-yaml/main.go)
     * [Bind Form](request-body/read-form/main.go)
+        * [Checkboxes](request-body/read-form/checkboxes/main.go)
     * [Bind Query](request-body/read-query/main.go)
     * [Bind Headers](request-body/read-headers/main.go)
     * [Bind Params](request-body/read-params/main.go)
diff --git a/_examples/request-body/read-form/checkboxes/main.go b/_examples/request-body/read-form/checkboxes/main.go
new file mode 100644
index 00000000..bd9994dc
--- /dev/null
+++ b/_examples/request-body/read-form/checkboxes/main.go
@@ -0,0 +1,32 @@
+package main
+
+import "github.com/kataras/iris/v12"
+
+func main() {
+	app := iris.New()
+	app.RegisterView(iris.HTML("./templates", ".html"))
+
+	app.Get("/", showForm)
+	app.Post("/", handleForm)
+
+	app.Listen(":8080")
+}
+
+func showForm(ctx iris.Context) {
+	ctx.View("form.html")
+}
+
+type formExample struct {
+	Colors []string `form:"colors[]"` // or just colors, it'll work as expected.
+}
+
+func handleForm(ctx iris.Context) {
+	var form formExample
+	err := ctx.ReadForm(&form)
+	if err != nil {
+		ctx.StopWithError(iris.StatusBadRequest, err)
+		return
+	}
+
+	ctx.JSON(iris.Map{"Colors": form.Colors})
+}
diff --git a/_examples/request-body/read-form/checkboxes/templates/form.html b/_examples/request-body/read-form/checkboxes/templates/form.html
new file mode 100644
index 00000000..aaaf6821
--- /dev/null
+++ b/_examples/request-body/read-form/checkboxes/templates/form.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Select a color</title>
+</head>
+<body>
+    <form action="/" method="POST">
+        <p>Select one or more colors</p>
+    
+        <label for="red">Red</label>
+        <!-- name can be "colors" too -->
+        <input type="checkbox" name="colors[]" value="red" id="red">
+        <label for="green">Green</label>
+        <input type="checkbox" name="colors[]" value="green" id="green">
+        <label for="blue">Blue</label>
+        <input type="checkbox" name="colors[]" value="blue" id="blue">
+        <input type="submit">
+    </form>
+</body>
+</html>
\ No newline at end of file
diff --git a/go.mod b/go.mod
index ae0a000b..d3e1a08e 100644
--- a/go.mod
+++ b/go.mod
@@ -17,7 +17,7 @@ require (
 	github.com/iris-contrib/httpexpect/v2 v2.0.5
 	github.com/iris-contrib/jade v1.1.4
 	github.com/iris-contrib/pongo2 v0.0.1
-	github.com/iris-contrib/schema v0.0.5
+	github.com/iris-contrib/schema v0.0.6
 	github.com/json-iterator/go v1.1.10
 	github.com/kataras/blocks v0.0.2
 	github.com/kataras/golog v0.1.2