System configuration fields

There are different field types for Magento’s system configuration. These are for example:

  • Button
  • Checkboxes
  • Checkbox
  • Date
  • File
  • Hidden
  • Imagefile
  • Image
  • Label
  • Link
  • Multiline
  • Multiselect
  • Note
  • Obscure
  • Password
  • Radio
  • Radios
  • Reset Select
  • Submit
  • Textarea
  • Text
  • Time

The following snippets show you how to add them to your system.xml:

  • Enable selection (yes/no):
    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">                    
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>
                            <enabled translate="label" module="asksheldon_module">
                                <label>Enable</label>
                                <frontend_type>select</frontend_type>
                                <source_model>adminhtml/system_config_source_yesno</source_model>
                                <sort_order>10</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>0</show_in_store>
                            </enabled>                        
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>
  • Multiselect (customer groups):
    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">                    
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>                        
                            <customer_groups translate="label comment">
                                <label>Customer groups</label>
                                <frontend_type>multiselect</frontend_type>
                                <source_model>adminhtml/system_config_source_customer_group</source_model>
                                <sort_order>11</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>0</show_in_store>
                                <comment>Groups for Friends &amp; Family discounts.</comment>
                            </customer_groups>             
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>
  • Product Type Selector:
    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">                    
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>                        
                            <type translate="label">
                                <label>Default product type</label>
                                <frontend_type>multiselect</frontend_type>
                                <!-- or 
                                <frontend_type>select</frontend_type>
                                -->
                                <source_model>sns_productadministration/adminhtml_source_product_type</source_model>
                                <sort_order>2</sort_order>
                                <show_in_default>1</show_in_default>
                            </type>                
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>
    

     

  • Website multiselect:
    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">                    
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>                        
                            <default_websites>
                                <label>Default Websites</label>
                                <frontend_type>multiselect</frontend_type>
                                <sort_order>4</sort_order>
                                <show_in_default>1</show_in_default>
                                <source_model>adminhtml/system_config_source_website</source_model>
                                <validate>required-entry</validate>
                                <comment>Default website(s) products are associated with</comment>
                            </default_websites>
                            <default_websites_abo>
                                <label>Default Websites ABO</label>
                                <frontend_type>multiselect</frontend_type>
                                <sort_order>5</sort_order>
                                <show_in_default>1</show_in_default>
                                <source_model>adminhtml/system_config_source_website</source_model>
                                <validate>required-entry</validate>
                                <comment>Website(s) products with ABO Flag are associated with</comment>
                            </default_websites_abo>
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>
  • Stores
    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">                    
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>                        
                             <stores translate="label">
                                <label>Stores</label>
                                <frontend_type>select</frontend_type>
                                <source_model>adminhtml/System_config_source_store</source_model>
                                <sort_order>r</sort_order>
                                <show_in_default>1</show_in_default>
                            </stores>
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>
  • Text (input type=”text):
    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>
                            <client_id translate="label" module="asksheldon_module">
                                <label>Nice Label</label>
                                <frontend_type>text</frontend_type>
                                <sort_order>20</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>1</show_in_store>    
                            </client_id>
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>
  • Textarea:
    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">                    
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>                        
                            <channel_id_category_root_map>
                                <label>Channel ID to Category Root Mapping</label>
                                <frontend_type>textarea</frontend_type>
                                <sort_order>2</sort_order>
                                <show_in_default>1</show_in_default>
                                <validate>required-entry</validate>
                                <comment>Format per Row: CHANELID; ROOTID, ROOTID, ROOTID</comment>
                            </channel_id_category_root_map>          
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>

     

  • Dependencies:
    You can define dependencies to other configuration fields like this:

    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">                    
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>
                            <enabled translate="label" module="asksheldon_module">
                                <label>Enable</label>
                                <frontend_type>select</frontend_type>
                                <source_model>adminhtml/system_config_source_yesno</source_model>
                                <sort_order>10</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>0</show_in_store>
                            </enabled> 
                            <client_id translate="label" module="asksheldon_module">
                                <label>Nice Label</label>
                                <frontend_type>text</frontend_type>
                                <sort_order>20</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>1</show_in_store>    
                                <!--/////////////////////////////////////////-->
                                <depends><enabled>1</enabled></depends>
                                <!--/////////////////////////////////////////-->
                            </client_id>                       
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>

    The field cliend_id is visible only if the enable selection was set to yes (1).

  • Validation:
    You can use build in field Validation for field like that:

    <?xml version="1.0"?>
    <config>
        <sections>
            <asksheldon_module translate="label" module="asksheldon_module">
                <label>Asksheldon Module Tab-Entry</label>
                <tab>asksheldon_module_tab</tab>
                <frontend_type>text</frontend_type>
                <sort_order>20</sort_order>
                <show_in_default>1</show_in_default>
                <groups>
                    <general translate="label">                    
                        <label>General</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <fields>                        
                            <client_id translate="label" module="asksheldon_module">
                                <label>Nice Label</label>
                                <frontend_type>text</frontend_type>
                                <sort_order>20</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>1</show_in_store>    
                                <!--/////////////////////////////////////////-->
                                <validate>required-entry</validate>
                                <!--/////////////////////////////////////////-->
                            </client_id>                       
                        </fields>
                    </general>
                </groups>
            </asksheldon_module>
        </sections>
    </config>
    

    The validate tag adds a class to the eventual input element. Here are the standard tests that come with Magento’s form validation. They work with config fields and FE-forms (Varien_Data_Form).

    • required-entry
    • validate-admin-password
    • validate-ajax
    • validate-alpha
    • validate-alphanum
    • validate-cc-cvn
    • validate-cc-exp
    • validate-cc-number
    • validate-cc-type
    • validate-cc-type-select validate-clean-url
    • validate-code
    • validate-cpassword
    • validate-css-length
    • validate-currency-dollar
    • validate-data
    • validate-date
    • validate-date-au
    • validate-digits
    • validate-email
    • validate-fax
    • validate-greater-than-zero
    • validate-identifier
    • validate-length
    • validate-new-password
    • validate-not-negative-number
    • validate-number
    • validate-one-required
    • validate-one-required-by-name
    • validate-password
    • validate-percents
    • validate-phone
    • validate-select
    • validate-ssn
    • validate-state
    • validate-street
    • validate-url
    • validate-xml-identifier
    • validate-zero-or-greater
    • validate-zip
    • validate-zip-international
    • validate-length minimum-length-9 maximum-length-9
  • t.b.c

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.