{"record":{"id":"4a5fce4f5a0ace4e","repo":"sveltejs/kit","slug":"form-contained-a-field-that-wasn-t-created-with-fo","errorCode":null,"errorMessage":"Form contained a field that wasn't created with form.fields.as(...): ${name}","messagePattern":"Form contained a field that wasn't created with form\\.fields\\.as\\(\\.\\.\\.\\): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/form-utils.js","lineNumber":37,"sourceCode":"\n/**\n * Separates a form field's path from the metadata encoded in its name.\n * @param {string} form_id\n * @param {string} key\n * @returns {{ name: string; type: 'number' | 'boolean' | null; is_array: boolean }}\n */\nexport function parse_form_key(form_id, key) {\n\tconst suffix = '/' + form_id;\n\tlet name = key;\n\tlet image_coordinate = '';\n\n\tif (name.startsWith('i:') && (name.endsWith(suffix + '.x') || name.endsWith(suffix + '.y'))) {\n\t\timage_coordinate = name[name.length - 1];\n\t\tname = name.slice(0, -2);\n\t}\n\n\tif (!name.endsWith(suffix)) {\n\t\tthrow new Error(`Form contained a field that wasn't created with form.fields.as(...): ${name}`);\n\t}\n\n\tname = name.slice(0, -suffix.length);\n\n\t/** @type {'number' | 'boolean' | null} */\n\tlet type = null;\n\n\tif (name.startsWith('n:')) {\n\t\tname = name.slice(2);\n\t\ttype = 'number';\n\t} else if (name.startsWith('b:')) {\n\t\tname = name.slice(2);\n\t\ttype = 'boolean';\n\t} else if (name.startsWith('i:')) {\n\t\tname = name.slice(2);\n\t\ttype = 'number';\n\t}\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/form-utils.js#L19-L55","documentation":"SvelteKit form fields created via form.fields.as(...) are serialized with a special 'i:' prefixed, suffixed key encoding their type and metadata. parse_form_key decodes these keys during submission handling; a field name lacking the expected suffix was not produced by form.fields.as(...) and cannot be parsed.","triggerScenarios":"Submitting a form containing a raw <input> with a hand-written name attribute mixed with generated fields; a field whose name attribute was manually modified after generation; progressive-enhancement forms posting fields the library didn't create.","commonSituations":"Adding a hidden input or checkbox by hand to an enhanced form; renaming generated name attributes for styling/testing tools; upgrading SvelteKit so old markup no longer matches the current suffix format.","solutions":["Create all fields with form.fields.as(...) and use the generated name attributes verbatim.","Remove or rename extra hand-written inputs so they do not collide with library-managed field names, and exclude them from parsing.","Regenerate the form markup after a SvelteKit version upgrade so the encoded field format matches the runtime."],"exampleFix":"// before\n<input name=\"email\" />\n// after\n<input name={fields.email.as('email')} />","handlingStrategy":"validation","validationCode":"for (const el of form.elements) {\n  if (el.name && !isLibraryManagedName(el.name)) {\n    throw new Error(`unmanaged field in enhanced form: ${el.name}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await handle_submit(...);\n} catch (e) {\n  if (e.message.includes(\"form.fields.as(...):\")) {\n    return fail(400, { error: 'Form contains unmanaged fields' });\n  }\n  throw e;\n}","preventionTips":["Use form.fields.as(...) for every field in an enhanced form and never hand-write name attributes for managed fields.","Do not rename generated name attributes for testing tools; select by other attributes instead.","Regenerate form markup after SvelteKit upgrades."],"tags":["forms","field-encoding","api-misuse"],"backgroundTag":"unmanaged-form-field","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}