diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-09-29 19:10:23 -0400 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-09-29 19:10:23 -0400 |
commit | e250d681fe1ad6fb2aac071feaf00baa3e32b5bb (patch) | |
tree | 3c354e5a0c12e412821ee80869856439f043fd9b /system/admin/server.go | |
parent | ce0750cfda5e207a03dacd7bf115cfc6e2ce367f (diff) |
added parsing and formatting code for inbound data formatted specially for gorilla/schema struct decoding. these values are normalized for db insertion
Diffstat (limited to 'system/admin/server.go')
-rw-r--r-- | system/admin/server.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/system/admin/server.go b/system/admin/server.go index 730561a..46e1dfa 100644 --- a/system/admin/server.go +++ b/system/admin/server.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net/http" + "strings" "github.com/nilslice/cms/content" "github.com/nilslice/cms/management/editor" @@ -99,6 +100,28 @@ func init() { cid := req.FormValue("id") t := req.FormValue("type") + + // check for any multi-value fields (ex. checkbox fields) + // and correctly format for db storage. Essentially, we need + // fieldX.0: value1, fieldX.1: value2 => fieldX: []string{value1, value2} + var discardKeys []string + for k, v := range req.PostForm { + if strings.Contains(k, ".") { + key := strings.Split(k, ".")[0] + + if req.PostForm.Get(key) == "" { + req.PostForm.Set(key, v[0]) + discardKeys = append(discardKeys, k) + } else { + req.PostForm.Add(key, v[0]) + } + } + } + + for _, discardKey := range discardKeys { + req.PostForm.Del(discardKey) + } + id, err := db.Set(t+":"+cid, req.PostForm) if err != nil { fmt.Println(err) |