I’m trying to add extra attributes to CMS pages. I am able to add these extra fields by following the help at http://blog.flexishore.com/2011/08/add-custom-field-to-cms-page/.
However, I cannot add images as the form for CMS pages does not have the enctype=”multipart/form-data”. To get around this I am having to create a local copy of the original Magento file. \app\code\local\Mage\Adminhtml\Block\Cms\Page\Edit\Form.php
Ideally, I would like to inject the enctype using the observer. I have trolled around everywhere and haven’t come across a suitable solution.
I was hoping to be able to add something like $form->setHtmlAttributes(‘enctype’, ‘multipart/form-data’)
public function prepareFormMainTab(Varien_Event_Observer $observer)
{
$form = $observer->getEvent()->getForm();
$fieldset = $form->addFieldset('fieldset', array(
'legend' => 'CMS Extras',
'class' => 'fieldset-wide'
)
);
$fieldset->addField('imagefile', 'image', array(
'name' => 'imagefile',
'label' => 'Image',
'title' => 'Image'
));
}
I found the solution.
First, I extended the Mage_Adminhtml and Mage_Cms modules. Somehow, the modification works even without doing this! Maybe someone could explain why.
I rewrite the Adminhtml block.
I copied \app\code\core\Mage\Adminhtml\Block\Cms\Page\Edit\Form.php to \app\code\local\Myname\Mymodule\Block\Adminhtml\Cms\Page\Edit\Form.php and added the enctype for the form.
NOTE
Though I am able to get the desired result, I am unable to understand how.