{"record":{"id":"96dc8571ab546b74","repo":"kataras/iris","slug":"empty-form-field","errorCode":null,"errorMessage":"empty form field","messagePattern":"empty form field","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"context/context.go","lineNumber":2918,"sourceCode":"\t\t\t\treturn is\n\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t}\n\n\t// ErrEmptyForm is returned by\n\t// - `context#ReadForm`\n\t// - `context#ReadQuery`\n\t// - `context#ReadBody`\n\t// when the request data (form, query and body respectfully) is empty.\n\tErrEmptyForm = errors.New(\"empty form\")\n\n\t// ErrEmptyFormField reports whether a specific field exists but it's empty.\n\t// Usage: errors.Is(err, ErrEmptyFormField)\n\t// See postValue method. It's only returned on parsed post value methods.\n\tErrEmptyFormField = errors.New(\"empty form field\")\n\n\t// ConnectionCloseErrorSubstr if at least one of the given\n\t// substrings are found in a net.OpError:os.SyscallError error type\n\t// on `IsErrConnectionReset` then the function will report true.\n\tConnectionCloseErrorSubstr = []string{\n\t\t\"broken pipe\",\n\t\t\"connection reset by peer\",\n\t}\n\n\t// IsErrConnectionClosed reports whether the given \"err\"\n\t// is caused because of a broken connection.\n\tIsErrConnectionClosed = func(err error) bool {\n\t\tif err == nil {\n\t\t\treturn false\n\t\t}\n\n\t\tif opErr, ok := err.(*net.OpError); ok {\n\t\t\tif syscallErr, ok := opErr.Err.(*os.SyscallError); ok {","sourceCodeStart":2900,"sourceCodeEnd":2936,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/context.go#L2900-L2936","documentation":"ErrEmptyFormField is a sentinel error (use with errors.Is) returned by the Context's post-value methods (PostValue*, backed by postValue) when a specific form field exists in the parsed request body but its value is an empty string. It is only produced by the parsed post-value methods, not by generic form/query lookups. It lets callers distinguish 'field present but empty' from 'field absent' (which returns the zero value / ErrEmptyForm for the whole body).","triggerScenarios":"Calling ctx.PostValue(\"field\"), ctx.PostValueInt, ctx.PostValueInt64, ctx.PostValueFloat64, ctx.PostValueBool, ctx.PostValueTime, etc. when the multipart/urlencoded body was parsed and contains the field key but the client submitted it with an empty value (e.g. <input name=\"email\" value=\"\"> or email=).","commonSituations":"HTML forms where the user left an optional input blank and the browser still submits the key; API clients sending empty multipart fields; mobile clients serializing every struct field including empty strings; forgetting that PostValue treats empty-string-present differently from a missing key.","solutions":["Check the error with errors.Is(err, context.ErrEmptyFormField) and decide whether an empty value is acceptable for that field.","Use ctx.PostValueDefault(\"field\", \"fallback\") (or read via ctx.FormValue/ctx.FormValues and validate yourself) so an empty field yields a default instead of the sentinel error.","If the whole body may be empty, also guard errors.Is(err, context.ErrEmptyForm) before inspecting individual fields.","Validate on the client side (required/minlength attributes) or reject earlier with a middleware that checks required form fields."],"exampleFix":"// before\nemail, err := ctx.PostValue(\"email\")\nif err != nil {\n    return err\n}\n\n// after\nemail, err := ctx.PostValue(\"email\")\nif errors.Is(err, context.ErrEmptyFormField) || errors.Is(err, context.ErrEmptyForm) {\n    email = \"\" // or a default / skip optional field\n} else if err != nil {\n    return err\n}","handlingStrategy":"validation","validationCode":"if vals, err := ctx.FormValues(); err == nil {\n    if v, ok := vals[\"email\"]; !ok || strings.TrimSpace(v[0]) == \"\" {\n        // field missing or empty: handle before calling PostValue\n    }\n}","typeGuard":"func isErrEmptyFormField(err error) bool {\n    return errors.Is(err, context.ErrEmptyFormField) || errors.Is(err, context.ErrEmptyForm)\n}","tryCatchPattern":"v, err := ctx.PostValue(\"email\")\nif errors.Is(err, context.ErrEmptyFormField) {\n    v = \"\" // treat as optional\n} else if err != nil {\n    ctx.StatusCode(http.StatusBadRequest)\n    return\n}","preventionTips":["Use PostValueDefault for optional fields so empty values fall back instead of erroring.","Distinguish missing-key vs empty-value handling in your form contract and document it.","Add client-side required/maxlength validation to reduce empty submissions.","Always compare with errors.Is, never ==, since the error may be wrapped."],"tags":["form-data","http","request-parsing","iris"],"backgroundTag":"empty-form-field","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}