{"record":{"id":"e4a7bd8625058982","repo":"phalcon/cphalcon","slug":"unknown-form-element-type-type","errorCode":null,"errorMessage":"Unknown form element type \"{type}\"","messagePattern":"Unknown form element type \"(.+?)\"","errorType":"exception","errorClass":"Phalcon\\Forms\\Exceptions\\UnknownFormElementType","httpStatus":null,"severity":"error","filePath":"phalcon/Forms/FormsLocator.zep","lineNumber":125,"sourceCode":"            let instance = {factory}(null);\n            let this->instances[name] = instance;\n        }\n\n        return instance;\n    }\n\n    /**\n     * Returns the factory callable for the given element type.\n     *\n     * @param string $type\n     *\n     * @return callable\n     * @throws Exception\n     */\n    public function getElement(string type)\n    {\n        if !isset this->elements[type] {\n            throw new UnknownFormElementType(type);\n        }\n\n        return this->elements[type];\n    }\n\n    /**\n     * Checks whether a named form factory is registered.\n     *\n     * @param string $name\n     *\n     * @return bool\n     */\n    public function has(string name) -> bool\n    {\n        return isset this->factories[name];\n    }\n\n    /**","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Forms/FormsLocator.zep#L107-L143","documentation":"Thrown by Phalcon\\Forms\\FormsLocator::getElement() when the element type string is not present in the element factory registry. The locator seeds default types ('text', 'email', 'select', 'textarea', ...) used by Form::load() to build elements from a schema; any type outside that map — including a wrongly capitalized one — is rejected because no factory exists for it.","triggerScenarios":"A schema entry with \"type\": \"Text\" instead of lowercase \"text\"; a custom type such as 'colorpicker' referenced by a schema without a prior $locator->setElement('colorpicker', $factory); a typo like 'textara'.","commonSituations":"Schema-driven forms (ArrayLoader/JsonLoader/YamlLoader via Form::load()) where type strings drift from the registry; adding custom element types but forgetting the setElement() registration; upgrading Phalcon versions where the set of default types changed.","solutions":["Normalize the schema type to lowercase and match a registered key exactly (check, checkgroup, date, email, file, hidden, numeric, password, radio, radiogroup, select, submit, text, textarea)","Register custom types before loading the schema: $locator->setElement('colorpicker', fn(string $name, array $options, array $attrs) => new ColorPicker($name, $options, $attrs))","Guard with $locator->hasElement($type) before calling getElement()","Validate schema types against hasElement() during a build or deploy step"],"exampleFix":"// before — schema uses \"type\": \"Text\"\n[\n  { \"type\": \"Text\", \"name\": \"email\" }\n]\n\n// after\n[\n  { \"type\": \"text\", \"name\": \"email\" }\n]\n\n// or register the custom type\n$locator->setElement('colorpicker', fn(string $name, array $options, array $attrs) => new ColorPicker($name, $options, $attrs));","handlingStrategy":"validation","validationCode":"$type = strtolower((string) $definition['type']);\n\nif (!$locator->hasElement($type)) {\n    // register it or reject the schema early with a precise message\n    throw new \\InvalidArgumentException(\"Unknown element type '{$type}' at index {$index}\");\n}\n\n$factory = $locator->getElement($type);","typeGuard":"/** @param mixed $type */\nfunction isValidElementType(\\Phalcon\\Forms\\FormsLocator $locator, $type): bool\n{\n    return is_string($type)\n        && $type !== ''\n        && $locator->hasElement(strtolower($type));\n}","tryCatchPattern":"try {\n    $factory = $locator->getElement($type);\n} catch (\\Phalcon\\Forms\\Exceptions\\UnknownFormElementType $e) {\n    // log the schema type and skip the entry, or fail the whole load\n    error_log($e->getMessage());\n    continue;\n}","preventionTips":["Normalize schema type strings with strtolower before use","Register custom element types via setElement() in the same bootstrap that builds the locator","Validate schema files against hasElement() in a CI lint step"],"tags":["phalcon","forms","element-type","factory","schema"],"backgroundTag":"unknown-type-identifier","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}