{"record":{"id":"1fdf3796734c28f8","repo":"sveltejs/kit","slug":"form-cannot-contain-duplicated-keys-field-nam","errorCode":null,"errorMessage":"Form cannot contain duplicated keys — \"${field.name}\" has ${entries.length} values","messagePattern":"Form cannot contain duplicated keys — \"(.+?)\" has (.+?) values","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/form-utils.js","lineNumber":100,"sourceCode":" */\nexport function convert_formdata(form_id, data) {\n\t/** @type {Record<string, any>} */\n\tconst result = {};\n\n\tfor (const field_name of data.keys()) {\n\t\t/** @type {any[]} */\n\t\tconst values = data.getAll(field_name);\n\n\t\tconst field = parse_form_key(form_id, field_name);\n\n\t\t// an empty `<input type=\"file\">` will submit a non-existent file, bizarrely\n\t\tconst entries = values.filter(\n\t\t\t(entry) => typeof entry === 'string' || entry.name !== '' || entry.size > 0\n\t\t);\n\t\tif (entries.length === 0 && !field.is_array) continue;\n\n\t\tif (entries.length > 1 && !field.is_array) {\n\t\t\tthrow new Error(\n\t\t\t\t`Form cannot contain duplicated keys — \"${field.name}\" has ${entries.length} values`\n\t\t\t);\n\t\t}\n\n\t\tset_nested_value(\n\t\t\tresult,\n\t\t\tfield,\n\t\t\tcoerce_form_value(field.type, field.is_array ? entries : entries[0])\n\t\t);\n\t}\n\n\treturn result;\n}\n\nexport const BINARY_FORM_CONTENT_TYPE = 'application/x-sveltekit-formdata';\nconst BINARY_FORM_VERSION = 0;\nconst HEADER_BYTES = 1 + 4 + 2;\n/**","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/form-utils.js#L82-L118","documentation":"convert_formdata turns submitted FormData into the typed form object. A non-array field must yield exactly one value; when the same encoded field key appears with multiple entries and the field was not declared as an array, the conversion is ambiguous and the library throws.","triggerScenarios":"Submitting a form where a scalar field's name is duplicated (two inputs sharing the same generated name) while the field was created without array semantics; accidentally rendering an input twice (e.g. once in a modal and once in the base form).","commonSituations":"Copy-pasted inputs with identical names; a select multiple posting multiple values into a scalar field; duplicated markup from both no-JS fallback and enhanced layers both rendering the field.","solutions":["Ensure each scalar field name appears exactly once in the form, removing duplicate inputs.","If multiple values are intended, declare the field as an array (array field variant of form.fields.as).","For multi-select, use the matching array field type so multiple entries are accepted."],"exampleFix":"// before\n<input name={fields.tag.as('tag')} />\n<input name={fields.tag.as('tag')} />\n// after\n<input name={fields.tags.as('tags', { array: true })} multiple />","handlingStrategy":"validation","validationCode":"const counts = {};\nfor (const [key] of new FormData(form).entries()) counts[key] = (counts[key] ?? 0) + 1;\nconst dupes = Object.entries(counts).filter(([, n]) => n > 1 && !isArrayField(keyOf(n)));\nif (dupes.length) throw new Error(`duplicated scalar fields: ${dupes.map(([k]) => k).join(', ')}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give each scalar input a unique generated name.","Use array field declarations when the same key legitimately posts multiple values.","Check for duplicated markup when rendering both enhanced and no-JS fallback forms."],"tags":["forms","duplicate-key","data-conversion"],"backgroundTag":"duplicate-form-field-values","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}