0

I created an admin menu in magento2 which is linked to a new admin page. I would like to have my own configuration fields (some text fields) in this new page with a save button.

1 Answer 1

0

In your custom module create system.xml file on follwing path /app/code/Namespace/Module/etc/adminhtml/system.xml and add following code

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="tops" translate="label" sortOrder="10">
            <label>Delivery Message</label>
        </tab>
        <section id="cod" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <class>separator-top</class>
            <label>Delivery message</label>
            <tab>tops</tab>
            <resource>Namespace_Module::cod_config</resource>
            <group id="catalog" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>General Configuration</label>
                <field id="codenable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Display Text</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Text for delivery message</label>
                    <comment>This text will display on the product detail page under addto cart button.</comment>
                </field>
            </group>
        </section>
        <section id="category_slider" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <class>separator-top</class>
            <label>Category Slider</label>
            <tab>tops</tab>
            <resource>Namespace_Module::cod_config</resource>
            <group id="catalog_category" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>General Configuration</label>
                <field id="category_id" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Please enter category ids comma saperated.</label>
                    <comment>Only first 2 ids data will display on home page.</comment>
                </field>
            </group>
        </section>
    </system>
</config>

Now go to Stoere->Configuration you will get your section called Delivery Message

7
  • I created a new menu like 'Store' and created a page with link.How can I add the above mentioned code under that menu link opening page?
    – Ragesh VP
    Commented Nov 14, 2018 at 8:48
  • You need this section in configuration area or your custom page ?
    – user55548
    Commented Nov 14, 2018 at 9:11
  • yes.Custom page with a menu option
    – Ragesh VP
    Commented Nov 14, 2018 at 9:42
  • I create a menu which is linked to a new admin page. I would like to have my own configuration fields in this new page with a save button
    – Ragesh VP
    Commented Nov 14, 2018 at 9:47
  • In that case you need to create model, and table for save your data.
    – user55548
    Commented Nov 14, 2018 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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