{"record":{"id":"bf98ce84e26ee26b","repo":"phalcon/cphalcon","slug":"form-schema-definition-at-index-index-is-missing","errorCode":null,"errorMessage":"Form schema definition at index {index} is missing required key \"type\"","messagePattern":"Form schema definition at index (.+?) is missing required key \"type\"","errorType":"exception","errorClass":"Phalcon\\Forms\\Exceptions\\SchemaEntryMissingKey","httpStatus":null,"severity":"error","filePath":"phalcon/Forms/Loader/ArrayLoader.zep","lineNumber":64,"sourceCode":"        }\n\n        return this->definitions;\n    }\n\n    /**\n     * @param mixed $definition\n     * @param int   $index\n     *\n     * @throws Exception\n     */\n    protected function validateDefinition(var definition, int index) -> void\n    {\n        if typeof definition !== \"array\" {\n            throw new SchemaEntryNotArray(index);\n        }\n\n        if !isset definition[\"type\"] || empty definition[\"type\"] {\n            throw new SchemaEntryMissingKey(index, \"type\");\n        }\n\n        if !isset definition[\"name\"] || empty definition[\"name\"] {\n            throw new SchemaEntryMissingKey(index, \"name\");\n        }\n    }\n}\n","sourceCodeStart":46,"sourceCodeEnd":72,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Forms/Loader/ArrayLoader.zep#L46-L72","documentation":"ArrayLoader::validateDefinition() requires every definition array to carry a non-empty 'type' key, since the type selects the element factory used to instantiate the element. A definition missing 'type', or with an empty/falsy type value, throws SchemaEntryMissingKey reporting both the index and the key name 'type'.","triggerScenarios":"A schema entry like ['name' => 'email'] with no 'type' key; an entry with 'type' => '' or 'type' => 0; renaming the key in a generator (e.g. 'element' instead of 'type') without updating the schema.","commonSituations":"Hand-edited schema files where the type line was deleted; code that builds definitions dynamically and omits the type branch for some fields; schema produced by another tool with different key names.","solutions":["Add a non-empty 'type' key to the definition at the reported index, e.g. ['type' => 'text', 'name' => 'email']","If you generate definitions in code, assert isset($def['type']) && $def['type'] !== '' before passing them to the loader","Re-check the reported index in the exception message — it points at the exact entry"],"exampleFix":"// before\n[\n  ['name' => 'email']\n]\n\n// after\n[\n  ['type' => 'email', 'name' => 'email']\n]","handlingStrategy":"validation","validationCode":"foreach ($definitions as $index => $definition) {\n    if (!isset($definition['type']) || $definition['type'] === '') {\n        throw new \\InvalidArgumentException(\n            \"Schema entry {$index} is missing a non-empty 'type'\"\n        );\n    }\n}\n\n$defs = (new \\Phalcon\\Forms\\Loader\\ArrayLoader($definitions))->load();","typeGuard":"function hasValidType(array $definition): bool\n{\n    return isset($definition['type'])\n        && is_string($definition['type'])\n        && $definition['type'] !== '';\n}","tryCatchPattern":"try {\n    $defs = (new \\Phalcon\\Forms\\Loader\\ArrayLoader($definitions))->load();\n} catch (\\Phalcon\\Forms\\Exceptions\\SchemaEntryMissingKey $e) {\n    // e->getMessage() names index and key ('type'); route it to the schema author\n    $logger->error($e->getMessage());\n    throw $e;\n}","preventionTips":["Write a small schema unit test that loads every bundled form schema at CI time","Prefer generating definitions from typed PHP arrays so missing keys fail statically","Treat the 'type' key as required in any schema documentation and example files"],"tags":["phalcon","forms","schema","missing-key","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}