3

I have a custom module that adds a field to an element in

<?php

class NS_MN_Block_Cms_Page_Edit_Tab_Main extends Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Main
{

public function _prepareForm()
{
parent::_prepareForm();

 $fieldset = $this->getForm()->getElements()->searchById('base_fieldset');

$fieldset->addField('bar', 'text',
    array(
        'label' => Mage::helper('cms')->__('BaR'),
        'class' => 'input-text',
        'name'  => 'bar',
        'required' => false
    )
);
return $this;
}
}

I have added the bar field into the cms_page table and the field is rendered, but when I save the cms page, the field is not saved to the database.

Could anyone tell me what I am overlooking here?

Pang
  • 9,564
  • 146
  • 81
  • 122
Jack
  • 185
  • 4
  • 12

2 Answers2

9

You need to remember to flush your cache. This one has caught me out a few times before.

Go into System > Cache Management and click both flush buttons.

Log out of the admin and log back in. Everything should function as expected.

Magento Guy
  • 2,493
  • 1
  • 16
  • 13
  • Cache is disabled so there is no need for me to flush the cache – Jack Mar 31 '12 at 00:42
  • 3
    That's incorrect, actually. You may have all cache types disabled for caching the fronted to the user, but "Flushing the cache" != "Refreshing the cache". If you're still having this issue. Do as I said in my answer. But it looks like you've accepted my answer anyhow. Thanks! – Magento Guy Apr 01 '12 at 09:03
  • The kicker for me was that I had to log out and then log back in. For a reason that I can't quite figure out, clearing the cache wasn't enough. Wasted a half hour on that! – Phil Birnie Mar 12 '14 at 02:26
1

Have you added the field to the database? Having the field in the form is one step, but in order to persist the data it must be able to live in a column in the DB. Once the field is in the DB, you might have to change the controller to recognize the new field, but it might already work for all fields. If it is already doing a setData($data) where $data is all received form data, you should be fine.

Max
  • 8,671
  • 4
  • 33
  • 46
  • Sorry, by the `cms_page` table I was referring to the database. – Jack Mar 29 '12 at 11:09
  • In that case, look into the `controller` that handles the save. – Max Mar 29 '12 at 11:20
  • Thanks for your help Max. On closer inspection it appears it is saving it into the Database, but it is not populating the text field once saved. – Jack Mar 31 '12 at 03:17