1

I'm trying to add a checkbox in the newsletter template edit form. Modifying the class Mage_Adminhtml_Block_Newsletter_Template_Edit_Form works, but of course I would rewrite the form in my own module to preserve upgradeability. I've added this code in config.xml

 <blocks>
            <adminhtml>
                <rewrite>
                    <newsletter_template_edit_form>Apedic_NewProductsByMail_Block_Adminhtml_Template_Edit_Form</newsletter_template_edit_form>
                </rewrite>
            </adminhtml>
        </blocks>

Copied the original class to Apedic_NewProductsByMail_Block_Adminhtml_Template_Edit_Form and added the checkbox

$fieldset->addField('cron', 'checkbox', array(
                'name' => 'cron',
                'label' => Mage::helper('newsletter')->__('Cron'),
                'value' => 1
            ));

However the checkbox doesn't appear. Where I'm wrong? thanks

2

The chances are you are doing the prepare form twice, once for your new class and once for the original class.

What happens if you simply copy the class Mage_Adminhtml_Block_Newsletter_Template_Edit_Form to your new class is that at the end of the function _prepareForm it will call the parent which in this case is Mage_Adminhtml_Block_Newsletter_Template_Edit_Form which will recreate the form without your new field.

The simplest thing to do here would be to call the parent first and then get the form and add your item so you function should look like the following.

protected function _prepareForm()
{
    parent::_prepareForm();
    $form = $this->getForm();
    $fieldset = $form->getElement('base_fieldset');
    $fieldset->->addField('cron', 'checkbox', array(
            'name' => 'cron',
            'label' => Mage::helper('newsletter')->__('Cron'),
            'value' => 1
        ));
    $this->setForm($form);
    return $this;
}

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.