// 更新基本信息 func createBaseInfoForm() *form.Form { description := form.NewTextField("description", "自我介绍", false).Max(100). Error("max-length", "自我介绍的字数不能多于{0}个").Field() name := form.NewCharField("name", "用户名", true).Min(2).Max(15). Error("required", "用户名必须填写"). Error("range", "用户名长度必须在{0}到{1}之间").Field() // add the fields to a form form := form.NewForm(description, name) return form }
/** * form */ func createTodoForm() *form.Form { // defined the field id := form.NewIntegerField("id", "Id", false).Range(1, 10). // {0} will replace with the min range value, // {1} will replace with the max range value, Error("range", "值必须在{0}到{1}之间").Field() // title title := form.NewTextField("title", "待办事项", true).Min(8).Max(200). Error("required", "必须填写事项内容"). Error("range", "字数必须在{0}到{1}之间").Field() // add the fields to a form form := form.NewForm(id, title) return form }
/** * 评论提交表单 */ func NewCommentSubmitForm() *form.Form { content := form.NewTextField("content", "内容", true).Min(8). Error("required", "内容必须填写"). Error("min", "内容长度必须大于{0}").Field() linkId := form.NewIntegerField("link_id", "链接id", true).Min(1). Error("required", "链接ID必须填写"). Error("invalid", "链接ID不正确").Field() parentId := form.NewIntegerField("parent_id", "父评论id", false). Error("invalid", "父评论ID不正确").Field() form := form.NewForm(linkId, parentId, content) return form }
/** * form */ func createTodoForm() *form.Form { // defined the field id := form.NewIntegerField("id", "Id", false).Range(1, 10). // {0} will replace with the min range value, // {1} will replace with the max range value, Error("range", "Value must between {0} and {1}").Field() // title title := form.NewTextField("title", "todo", true).Min(8).Max(200). Error("required", "Must write what to do"). Error("range", "Words must between {0} and {1}").Field() // add the fields to a form form := form.NewForm(id, title) return form }