octobercms/october · error · SystemException

The addFormField method should be called when defining…

Error message

The addFormField method should be called when defining fields inside a model. Try using addField, addTabField or addSecondaryTabField instead.

What it means

Developer-facing guard in the FormElement builder API: addFormField() was called while no tab section is active. Fields added directly to a fieldset from a model context must go through addField/addTabField/addSecondaryTabField, which manage tab sections; addFormField is for internal fieldset wiring.

Solutions

  1. Replace the addFormField() call with addField(), addTabField(), or addSecondaryTabField() as appropriate
  2. If implementing a custom fieldset flow, ensure a tab section is started before calling addFormField()
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/backend/widgets/form/IsFormElement.php:29 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/304e340909e04a55. Report an issue: GitHub.

Appendix: source

Thrown at modules/backend/widgets/form/IsFormElement.php:29

 *
 * @see \October\Contracts\Element\FormElement
 * @package october\backend
 * @author Alexey Bobkov, Samuel Georges
 */
trait IsFormElement
{
    /**
     * @var FieldsetDefinition|null activeTabSection where fields are currently being added
     */
    protected $activeTabSection = null;

    /**
     * addFormField adds a field to the fieldset
     */
    public function addFormField(string $fieldName, ?string $label = null): FieldDefinition
    {
        if ($this->activeTabSection === null) {
            throw new SystemException("The addFormField method should be called when defining fields inside a model. Try using addField, addTabField or addSecondaryTabField instead.");
        }

        $fieldObj = new FormField([
            'fieldName' => $fieldName,
            'label' => $label,
            'arrayName' => $this->arrayName,
            'idPrefix' => $this->getId()
        ]);

        $this->allFields[$fieldName] = $fieldObj;

        $this->activeTabSection->addField($fieldName, $fieldObj);

        return $fieldObj;
    }

    /**
     * getFormFieldset returns the current fieldset definition

View on GitHub (pinned to b608633a7e)