0

I am following this article, where i have a dropdown. But after submit my dropdown has alwasy the first option value, not the selected one. In my case the dropdown contains all of the cms pages. This is my code:

 class Mynamespace_Mymodule_Block_Adminhtml_Form_Field_Cmspage extends Mage_Core_Block_Html_Select
{
    public function _toHtml()
    {
        $options = Mage::getModel('cms/page')->getCollection()->toOptionArray();
        foreach ($options as $option) {
            $this->addOption($option['value'], $option['label']);
        }

        return parent::_toHtml();
    }

    public function setInputName($value)
    {
        return $this->setName($value);
    }
}

where my dropdown is genered. So any idea about that ? Thx in advance. This is the content of system.xml:

<config>
    <sections>
        <mynamespace_mymodule translate="label" module="mynamespace_mymodule">
            <label>CMS Success Page</label>
            <tab>customer</tab>
            <sort_order>1000</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <general translate="label" module="mynamespace_mymodule">
                    <label>Cms Success Page Assignment</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>10</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <cmspages translate="label">
                            <label>CMS Success Pages</label>
                            <frontend_model>mynamespace_mymodule/config_cmspages</frontend_model>
                            <backend_model>adminhtml/system_config_backend_serialized_array</backend_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>
                        </cmspages>
                    </fields>
                </general>
            </groups>
        </mynamespace_mymodule>
    </sections>
</config>
  • Could you also post the contents of system.xml file of your extension? That might help people to give some advice. – Yaroslav Rogoza Apr 22 '16 at 12:42
  • I updated my post , can u check it ? – Attila Naghi Apr 22 '16 at 12:52
0

If I understand you correctly, you need to choose some CMS pages and save their ID's in configuration for further use. In that case, you don't need a separate frontend model or backend model, only a source model. The config for your field should look like this one:

<cmspages translate="label">
    <label>CMS Success Pages</label>
    <frontend_type>multiselect</frontend_type
    <source_model>mynamespace_mymodule/config_source_pages</source_model>
    <sort_order>11</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</cmspages>

And the source model itself should look like:

class Mynamespace_Mymodule_Model_Config_Source_Pages
{
    protected $_options;

    public function toOptionArray($isMultiselect=false)
    {
        if (!$this->_options) {
            $this->_options = Mage::getModel('cms/page')->getCollection()->toOptionArray();
        }

        $options = $this->_options;
        if(!$isMultiselect){
            array_unshift($options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
        }

        return $options;
    }

}

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.