{"record":{"id":"d92b5fa2d6caaf0b","repo":"kataras/iris","slug":"erremptyformfield","errorCode":"ErrEmptyFormField","errorMessage":"%w: %s","messagePattern":"%w: %s","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"context/context.go","lineNumber":1912,"sourceCode":"func (ctx *Context) PostValues(name string) ([]string, error) {\n\t_, ok := ctx.form()\n\tif !ok {\n\t\tif !ctx.app.ConfigurationReadOnly().GetFireEmptyFormError() {\n\t\t\treturn nil, nil\n\t\t}\n\n\t\treturn nil, ErrEmptyForm // empty form.\n\t}\n\n\tvalues, ok := ctx.request.PostForm[name]\n\tif !ok {\n\t\treturn nil, ErrNotFound // field does not exist\n\t}\n\n\tif len(values) == 0 ||\n\t\t// Fast check for its first empty value (see below).\n\t\tstrings.TrimSpace(values[0]) == \"\" {\n\t\treturn nil, fmt.Errorf(\"%w: %s\", ErrEmptyFormField, name)\n\t}\n\n\tfor _, value := range values {\n\t\tif value == \"\" { // if at least one empty value, then perform the strip from the beginning.\n\t\t\tresult := make([]string, 0, len(values))\n\t\t\tfor _, value := range values {\n\t\t\t\tif strings.TrimSpace(value) != \"\" {\n\t\t\t\t\tresult = append(result, value) // we store the value as it is, not space-trimmed.\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif len(result) == 0 {\n\t\t\t\treturn nil, fmt.Errorf(\"%w: %s\", ErrEmptyFormField, name)\n\t\t\t}\n\n\t\t\treturn result, nil\n\t\t}\n\t}","sourceCodeStart":1894,"sourceCodeEnd":1930,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/context.go#L1894-L1930","documentation":"This error is returned by Context.PostValues-family lookup helpers (e.g. ctx.PostValueMany/PostValues) when a form field exists in the POST form data but its first value is empty or whitespace-only after trimming. The library wraps the sentinel ErrEmptyFormField and appends the offending field name so callers can distinguish 'field missing' (ErrNotFound) from 'field present but empty'.","triggerScenarios":"Calling ctx.PostValue(name)/PostValueMany/PostValueTrim where the multipart or urlencoded form contains the key but values[0] trims to \"\" (e.g. input left blank in the browser).","commonSituations":"HTML forms with optional text inputs submitted empty; automated clients sending 'field=' pairs; mobile apps posting empty strings instead of omitting keys.","solutions":["Check errors.Is(err, iris/context.ErrEmptyFormField) and treat it as a missing optional field rather than a hard failure.","Have the client omit the key entirely or send a real value; validate before submit.","Use ctx.PostValues and decide per-value semantics yourself if empty strings are meaningful.","For required fields, return a 400 with the field name extracted from the wrapped error message."],"exampleFix":"// before\nvals, err := ctx.PostValues(\"tags\")\nif err != nil { return err }\n// after\nvals, err := ctx.PostValues(\"tags\")\nif errors.Is(err, context.ErrEmptyFormField) {\n    vals = nil // treat empty as absent\n} else if err != nil {\n    return err\n}","handlingStrategy":"validation","validationCode":"if name := ctx.FormValue(\"tags\"); name == \"\" { /* treat as absent before calling PostValues */ }","typeGuard":"func isEmptyFormField(err error) bool { return errors.Is(err, context.ErrEmptyFormField) }","tryCatchPattern":"vals, err := ctx.PostValues(\"tags\")\nswitch {\ncase errors.Is(err, context.ErrEmptyFormField):\n    vals = nil\ncase err != nil:\n    return err\n}","preventionTips":["Treat ErrEmptyFormField and ErrNotFound separately with errors.Is","Have clients omit empty keys instead of sending blank values","Validate required vs optional fields in a shared form-binding struct"],"tags":["go","iris","form-data","validation"],"backgroundTag":"empty-form-field","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}