Creating custom tabs in the forms

This topic describes how you can create custom tabs in Control Panel.

To create custom tabs, you will have to:

  1. implement tab handlers as a class or functions;
  2. Register the tab event by calling AddeventHandler or RegisterModuleDependencies.

The class must implement the following methods:

  • The OnInit() method - returns an array with names or callback arrays of other methods. The array must contain the following keys:
    • TABSET - the tab set ID;
    • GetTabs - a callback array of a tab description method;
    • ShowTab - a callback array of a method returning the HTML code of a form page by the tab identifier;
    • Action - a callback array of a method that will process data received from the from;
    • Check - a callback array of a method that will check data received from the from.
  • All the methods returned by OnInit.
  • Any other methods used in the class or functions.

Example of a class implementing custom tabs

class CCustomOETabs
    function OnInit()
        return array(
        "TABSET" => "YYY",
        "GetTabs" => array("CCustomOETabs", "GetTabs"),
        "ShowTab" => array("CCustomOETabs", "ShowTab"),
        "Action" => array("CCustomOETabs", "Action"),
        "Check" => array("CCustomOETabs", "Check"),

    function Action($arArgs)
        // Data is stored. Perfom actions here.
        // Return true on success, or false otherwise.
        // In case of error, also call $GLOBALS["APPLICATION"]-> ThrowException("ERROR!!!");

    function Check($arArgs)
        // Data has not been stored yet. Perform various checks here.
        // Return true if data can be saved, or false otherwise.
        // If false, also call $GLOBALS["APPLICATION"]-> ThrowException("ERROR!!!");

    function GetTabs($arArgs)
        // SORT - specifies the insertion position (in terms of standard tabs).
      // If not specified, inserts after the last tab. $arTabs = array( array("DIV" => "edit1", "TAB" => "Custom tab 1", "ICON" => "sale", "TITLE" => "Custom tab 1", "SORT" => 1), ); return $arTabs; } function ShowTab($divName, $arArgs, $bVarsFromForm) { if ($divName == "edit1") { ?> <tr> <td width="40%">Custom field 1:</td> <td width="60%"><input type="text" name="custom_field_1"></td> </tr> <? } } }

All methods (except ShowTab) receive an array of arguments specified using in the  CAdminTabEngine class constructor or the CAdminTabEngine::SetArgs method. The format of an array returned by GetTabs is described here.

© «Bitrix24», 2001-2023