Redirecting the Newsletter Success Page

Sometimes, clients would like the newsletter success action to redirect to an actual page rather than just setting a message and redirecting to the referrer (the default action). Here, we override the newsletter controller and allow a CMS page to be set to the success page which allows the client to edit the content and also change the page at their will.

config.xml

<frontend>
		<routers>
			<newsletter>
				<args>
					<modules>
						<VanVault_Skin before="Mage_Newsletter">VanVault_Skin_Newsletter</VanVault_Skin>
					</modules>
				</args>
			</newsletter>
		</routers>
	</frontend>
 

The Controller

<?php
require_once(Mage::getModuleDir('controllers', 'Mage_Newsletter') . DS . 'SubscriberController.php');

class VanVault_Skin_Newsletter_SubscriberController extends Mage_Newsletter_SubscriberController{
	const XML_PATH_CMS_REDIRECT_PAGE = "newsletter/subscription/redirect_page";
	
	public function newAction(){
		parent::newAction();
		
		if($pageIdentifier = Mage::getStoreConfig(self::XML_PATH_CMS_REDIRECT_PAGE)){
			$this->_redirectUrl(Mage::helper('cms/page')->getPageUrl($pageIdentifier));
		}
	}
}

system.xml

<?xml version="1.0"?>
<config>
	<sections>
		<newsletter>
			<groups>
				<subscription>
					<fields>
						<redirect_page translate="label" module="vanvault">
							<label>CMS Redirect Page</label>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
							<frontend_type>select</frontend_type>
							<source_model>vanvault/adminhtml_system_config_source_cms_page</source_model>
							<sort_order>200</sort_order>
						</redirect_page>
					</fields>
				</subscription>
			</groups>
		</newsletter>
	</sections>
</config>

The System Config Source Class

We override the standard cms page selector (Mage_Adminhtml_Model_System_Config_Source_Cms_Page) to add a blank option at the start. This allows the default behaviour of the newsletter success action to remain if no option is selected.

<?php
class VanVault_Skin_Model_Adminhtml_System_Config_Source_Cms_Page extends Mage_Adminhtml_Model_System_Config_Source_Cms_Page{
	public function toOptionArray(){
		$options = parent::toOptionArray();
		array_unshift($options, array(
			'value' => '',
			'label' => Mage::helper('vanvault')->__('-- Please Select --')
		));
		
		return $options;
	}
		
}