[Mini Tutorial]
How to Add Basic Input Fields to Magento Admin Panel

Scope

This is going to be a quick crash guide to adding yes/no (boolean) fields or text input fields to the Magento administrative panel. This tutorial will assume that you already have a module ready to add admin fields to.

Related: Write Better Code: Tips to Keep Your Templates Clean

Using Access Control Lists (ACL)

Since we’re going to be adding a section to the admin panel, we need to give the ability to allow and disallow access to that section. We use Access Control Lists (ACL) for this.

Create a etc/adminhtml.xml in your module and insert this block of XML in there. Replace NAMESPACE with an identifier for your new section. Replace YOUR NEW SECTION with the name of your section that will store your fields.

<?xml version="1.0"?>
<config>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<NAMESPACE>
<title>YOUR NEW SECTION</title>
<sort_order>100</sort_order>
</NAMESPACE>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
view raw adminhtml.xml hosted with ❤ by GitHub

Adding Input Fields

Create etc/system.xml in your module and insert this snippet into it.

<?xml version="1.0"?>
<config>
<tabs>
<NAMESPACE translate="label" module="MODULE_NAME">
<label>YOUR NEW SECTION</label>
<sort_order>100</sort_order>
<class>NAMESPACE</class>
</NAMESPACE>
</tabs>
<sections>
<NAMESPACE translate="label" module="MODULE_NAME">
<label>SECTION NAME</label>
<tab>NAMESPACE</tab>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<GROUP_IDENTIFIER translate="label">
<label>GROUP NAME</label>
<comment>This is the text that appears above the fields. It provides description for what the fields pertain to.</comment>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<TEXT_FIELD translate="label">
<label>This is a text field</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</TEXT_FIELD>
<BOOLEAN_FIELD translate="label">
<label>This is a yes/no (boolean) selector</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>200</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</BOOLEAN_FIELD>
</fields>
</GROUP_IDENTIFIER>
</groups>
</NAMESPACE>
</sections>
</config>
view raw system.xml hosted with ❤ by GitHub

Replace NAMESPACE, and YOUR NEW SECTION with the values used in etc/adminhtml.xml.

Replace MODULE_NAME with your module’s model namespace.

Replace SECTION NAME with the name of the section. This is the tab in the navigation sidebar.

Replace GROUP NAME with the name of the group of fields. This is the title of the box that the fields are contained in.

Replace GROUP_IDENTIFIER, TEXT_FIELD, and BOOLEAN_FIELD with designations of your choosing. These last three values with determine the config path for when you retrieve config values.

Related: [Mini Tutorial] Adding Custom Links with local.xml

You’re Done!

You’re going to need to clear config caches, log out of Magento admin panel, and log back in before you can see the new fields. Set your values now.

Using Your Stored Config Values

After you’ve set a value in the Magento admin panel for the newly added field, you can access the value like this.

<?php
// the value for your text field
$text_field_value = Mage::getStoreConfig('NAMESPACE/GROUP_IDENTIFIER/TEXT_FIELD');
// the value for your yes/no (boolean) field
$boolean_field_value = Mage::getStoreConfig('NAMESPACE/GROUP_IDENTIFIER/BOOLEAN_FIELD');
view raw example.phtml hosted with ❤ by GitHub

Good luck!

Related: [Mini-Tutorial] Magento and WordPress Multisite Integration