{"record":{"id":"304e340909e04a55","repo":"octobercms/october","slug":"the-addformfield-method-should-be-called-when-defi","errorCode":null,"errorMessage":"The addFormField method should be called when defining fields inside a model. Try using addField, addTabField or addSecondaryTabField instead.","messagePattern":"The addFormField method should be called when defining fields inside a model\\. Try using addField, addTabField or addSecondaryTabField instead\\.","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/backend/widgets/form/IsFormElement.php","lineNumber":29,"sourceCode":" *\n * @see \\October\\Contracts\\Element\\FormElement\n * @package october\\backend\n * @author Alexey Bobkov, Samuel Georges\n */\ntrait IsFormElement\n{\n    /**\n     * @var FieldsetDefinition|null activeTabSection where fields are currently being added\n     */\n    protected $activeTabSection = null;\n\n    /**\n     * addFormField adds a field to the fieldset\n     */\n    public function addFormField(string $fieldName, ?string $label = null): FieldDefinition\n    {\n        if ($this->activeTabSection === null) {\n            throw new SystemException(\"The addFormField method should be called when defining fields inside a model. Try using addField, addTabField or addSecondaryTabField instead.\");\n        }\n\n        $fieldObj = new FormField([\n            'fieldName' => $fieldName,\n            'label' => $label,\n            'arrayName' => $this->arrayName,\n            'idPrefix' => $this->getId()\n        ]);\n\n        $this->allFields[$fieldName] = $fieldObj;\n\n        $this->activeTabSection->addField($fieldName, $fieldObj);\n\n        return $fieldObj;\n    }\n\n    /**\n     * getFormFieldset returns the current fieldset definition","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/backend/widgets/form/IsFormElement.php#L11-L47","documentation":"Error \"The addFormField method should be called when defining fields inside a model. Try using addField, addTabField or addSecondaryTabField instead.\" thrown in octobercms/october.","triggerScenarios":"Thrown at modules/backend/widgets/form/IsFormElement.php:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}