im actually goated
This commit is contained in:
@@ -3,7 +3,6 @@ package validation
|
||||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
@@ -32,18 +31,24 @@ func (f *FormGetter) GetList(key string) []string {
|
||||
}
|
||||
|
||||
func (f *FormGetter) GetMaps(key string) []map[string]string {
|
||||
var result []map[string]string
|
||||
for key, values := range f.r.Form {
|
||||
re := regexp.MustCompile(key + "\\[([0-9]+)\\]\\[([a-zA-Z]+)\\]")
|
||||
matches := re.FindStringSubmatch(key)
|
||||
results := map[string]map[string]string{}
|
||||
re := regexp.MustCompile(key + "\\[([0-9]+)\\]\\[([a-zA-Z_]+)\\]")
|
||||
for k, v := range f.r.Form {
|
||||
matches := re.FindStringSubmatch(k)
|
||||
if len(matches) >= 3 {
|
||||
index, _ := strconv.Atoi(matches[1])
|
||||
for index >= len(result) {
|
||||
result = append(result, map[string]string{})
|
||||
realKey := matches[1]
|
||||
field := matches[2]
|
||||
value := strings.Join(v, ",")
|
||||
if _, exists := results[realKey]; !exists {
|
||||
results[realKey] = map[string]string{}
|
||||
}
|
||||
result[index][matches[2]] = values[0]
|
||||
results[realKey][field] = value
|
||||
}
|
||||
}
|
||||
result := []map[string]string{}
|
||||
for _, v := range results {
|
||||
result = append(result, v)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user