// 如果保存失败,则返回错误信息 // 返回为 success, linkId, errors. // 如果success为false并且linkId大于0,则为提交的url已经存在. func Link_SaveForm(f *form.Form, userId int64, resubmit bool) (bool, int64, []string, map[string]interface{}) { var id int64 var m map[string]interface{} errorMsgs := make([]string, 0) if f.Valid() { m = f.CleanValues() if !resubmit { link, err := Link_GetByUrl(m["context"].(string)) if err == nil && link != nil && link.Id > 0 { errorMsgs = append(errorMsgs, "Url已经提交过") return false, link.Id, errorMsgs, nil } } m["topics"] = buildTopics(m["topics"].(string)) m["user_id"] = userId id = Link_SaveMap(m) if id > 0 { Topic_SaveTopics(m["topics"].(string), id) } else { errorMsgs = append(errorMsgs, golink.ERROR_DATABASE) } } else { errs := f.Errors() for _, v := range errs { errorMsgs = append(errorMsgs, v[0]+": "+v[1]) } } if len(errorMsgs) < 1 { return true, id, nil, m } return false, id, errorMsgs, nil }
// 如果保存失败,则返回错误信息 func Link_SaveForm(f *form.Form, userId int64) (bool, int64, []string) { var id int64 errorMsgs := make([]string, 0) if f.Valid() { m := f.CleanValues() m["topics"] = buildTopics(m["topics"].(string)) m["user_id"] = userId id = Link_SaveMap(m) if id > 0 { Topic_SaveTopics(m["topics"].(string), id) } else { errorMsgs = append(errorMsgs, golink.ERROR_DATABASE) } } else { errs := f.Errors() for _, v := range errs { errorMsgs = append(errorMsgs, v[0]+": "+v[1]) } } if len(errorMsgs) < 1 { return true, id, nil } return false, id, errorMsgs }
// 如果保存失败,则返回错误信息 func Comment_SaveForm(f *form.Form, userId int64) (bool, []string) { errorMsgs := make([]string, 0) if f.Valid() { m := f.CleanValues() m["user_id"] = userId id, err := Comment_SaveMap(m) if err != nil || id < 1 { errorMsgs = append(errorMsgs, golink.ERROR_DATABASE) } } else { errs := f.Errors() for _, v := range errs { errorMsgs = append(errorMsgs, v[1]) } } if len(errorMsgs) < 1 { return true, nil } return false, errorMsgs }