3

I've added a tab to the admin menu with our company's page, which enables the user to insert and define his own properties of our widget (input fields of secret and key). Now I would like magento's server to save these values upon clicking the page's 'save' button, and show them next time the user loads the page. previously we did that inside system.xml:

 field id="key" translate="label" type="text" showInDefault="1"  showInStore="1">
 field id="secret" translate="label" type="text" showInDefault="1"  showInStore="1">

I tried to translate this to .phtml (simple html input text) but not sure magento2 supports other formats except her attributes in xml files.

Ideas?

1

enter image description hereIn Magento 2, you can achieve this by using the same system.xml file placed under app/code/Vendor/Package/etc/adminhtml/system.xml

<?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="custom_module" translate="label" sortOrder="10">
            <label>Progos</label>
        </tab>
        <section id="custom_module_section" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Custom Module</label>
            <tab>custom_module</tab>
            <resource>Progos_Custom::custom_config</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>API Settings</label>
                <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Module Enable</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="api" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>API</label>
                    <comment>This is comment for this field.</comment>
                </field>
                <field id="secret" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Secret Key</label>
                    <comment>This is comment for this field.</comment>
                </field>
            </group>
        </section>
    </system> </config>

Please have a look at attached image too.

If you still have any confusion, let us know! Good Luck!

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.