Magento 2 add tab in admin form

When building a Magento extension or do a project in magento 2, some time you have to update a lot of data in a form so you need add new tab in form. For example, I want to build extension to Manager Members, The member has a lot of Information so I will group them to some group such as Base Information, Address Information , etc … .

Magento 2 add tab in admin form

In order to add new tab in admin form, you can do 2 task :
– Declare new Tab
– Create Tab

1. Declare new Tab

You can Declare new Tab in app/code/Vendor/Module/Block/Adminhtml/CustomData/Edit/Tabs.php.
For my example: I will add code to function _beforeToHtml() in file

namespace Magebay\Hello\Block\Adminhtml\Members\Edit;
use Magento\Backend\Block\Widget\Tabs as WidgetTabs;
class Tabs extends WidgetTabs
    // other functions 
    protected function _beforeToHtml()
       //other tabs 
                'label' => __('General'),
                'title' => __('General'),
                'content' => $this->getLayout()->createBlock(
                'active' => true
        return parent::_beforeToHtml();

2. Create Tab

Next , Will will add address fields to class ‘Magebay\Hello\Block\Adminhtml\Members\Edit\Tab\Info

namespace Magebay\Hello\Block\Adminhtml\Members\Edit\Tab;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;
use Magento\Framework\Data\FormFactory;
use Magento\Cms\Model\Wysiwyg\Config;
use Magebay\Hello\Model\System\Config\Status;
class Info extends Generic implements TabInterface
     * @var \Magento\Cms\Model\Wysiwyg\Config
    protected $_wysiwygConfig;
     * @var \Magebay\Hello\Model\System\Config\Status
    protected $_status;
     * @param Context $context
     * @param Registry $registry
     * @param FormFactory $formFactory
     * @param Config $wysiwygConfig
     * @param Status $status
     * @param array $data
    public function __construct(
        Context $context,
        Registry $registry,
        FormFactory $formFactory,
        Config $wysiwygConfig,
        Status $status,
        array $data = []
    ) {
        $this->_wysiwygConfig = $wysiwygConfig;
        $this->_status = $status;
        parent::__construct($context, $registry, $formFactory, $data);
     * Prepare form fields
     * @return \Magento\Backend\Block\Widget\Form
    protected function _prepareForm()
       /** @var $model \Magebay\Hello\Model\PostsFactory */
        $model = $this->_coreRegistry->registry('member_data');
        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create();
        $fieldset = $form->addFieldset(
            ['legend' => __('Address Information')]
        if ($model->getId()) {
                ['name' => 'address_id']
                'name'      => 'city',
                'label'     => __('City')
        $data = $model->getData();
        return parent::_prepareForm();

As you can see , I have added new tab in admin form . I hope the post is useful for you. We have a lot of great Magento extension like Magento Multi Vendor Marketplace Extension , Booking system Extension.if you want to have custom extension for your site, you can contact to