I have created a new admin module page in magento 2 using this link http://devdocs.magento.com/guides/v2.0/ext-best-practices/extension-coding/example-module-adminpage.html. Now I want to add two text boxes and a submit button in the same page. How can I do that?


You can create text boxes on admin page by creating form.php in this path yourvendor/modulename/block/form.php

Create _prepareForm() function and in that function define the structure of text boxes which you want to create.

Firstly you need to create fieldset and using that fieldset you can add new field.

For example try below code :

protected function _prepareForm()
        $model = $this->getModel();

        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create(
            ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]


        $fieldset = $form->addFieldset(
            ['legend' => __('General Information'), 'class' => 'fieldset-wide']

            ['name' => 'title', 'label' => __('Your Title'), 'title' => __('Your Title'), 'required' => true]

                'name' => 'description',
                'label' => __('Description'),
                'title' => __('Description'),
                'style' => 'height:36em',
                'required' => true

        return parent::_prepareForm();

After that load this block in your layout file where you want to show this fields.

run cache:clean command and check

  • How can I load this in to my helloworld.phtml – Vadivel Murugan M Nov 24 '16 at 10:39
  • @VadivelMuruganM for that you need to learn concept of model and controller better you can refer this link - ashsmith.io/magento2 – Manthan Dave Nov 24 '16 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.