Adding a custom field to Magento's subscription module

pixeltocode picture pixeltocode · Jul 1, 2010 · Viewed 30.7k times · Source

The newsletter subscription module in Magento has only one field (email) by default. After I add an extra field to the form (say country), how can I get the form data to show up in the Magento back-end and be sent as an email to a preset recipient? Thanks.

Answer

Roman Snitko picture Roman Snitko · Jun 21, 2011

If you want to add some custom fields for Magento newsletter subscriber (for example subscriber_name), you should do the following:

  • Add new column for newsletter_subscriber table
  • Add text input to newsletter template
  • Create observer for newsletter_subscriber_save_before event

In the observer you can get your custom field's value from request and assign it to subscriber's object:

public function newsletterSubscriberSave(Varien_Event_Observer $observer)
{
    $subscriber = $observer->getEvent()->getSubscriber();
    $name = Mage::app()->getRequest()->getParam('subscriber_name');

    $subscriber->setSubscriberName($name);

    return $this;
}


UPDATE:

Here is the detailed article explaining how to add Country field Also, I have created a free module, it is available on the GitHub