To add "Subscribe to Newsletter" checkbox on
Contact form, follow following steps:
1) Go to contacts/form.phtml
file of your selected theme.
2) Place following code in the file as per your requirement :
<input
type="checkbox" name="subscribe_newsletter"><?php
echo
Mage::helper('contacts')->__(' Subscribe to Newsletter ') ?>
3) Now go to \app\code\local\Mage\Contacts\controllers\IndexController.php
file
and put following code in postAction()
function :
Note: If you are not able to find Mage/Contacts.... folder in local directory please create new one and refer to the link (http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_create_a_local_copy_of_app_code_core_mage)
Note: If you are not able to find Mage/Contacts.... folder in local directory please create new one and refer to the link (http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_create_a_local_copy_of_app_code_core_mage)
/*Start
of code*/
if(isset($_POST['subscribe_newsletter'])){
$email = $_POST['email'];
$status =
Mage::getModel('newsletter/subscriber')->subscribe($email);
if
($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
Mage::getSingleton('customer/session')
->addSuccess($this->__('Confirmation request has been sent.'));
}
else
{
Mage::getSingleton('customer/session')
->addSuccess($this->__('Thank you for your newsletter subscription.'));
}
}
/*End of code*/
That’s it and you are done. Hopefully it will help you guys
as well.
Thanks!!!!!!!! Enjoy Programming J
Excellent is the only word i can give u for this wonderful blog, keep it up. I will come back again to read some more interesting things on this topic
ReplyDeleteThanks buddy!!!!
DeleteThis will be removed when you upgrade however. I suggest you app\code\local\Mage\Contacts\controllers\IndexController.php and edit that file
ReplyDeleteI have update the post. Thank you so much for making it correct and more meaningful!!!! :)
Deletei made my controller in app\code\local\Mage\Contacts\controllers\IndexController.php but while running it uses core controller.does not uses controller that i made.but contact form is working fine except for newsletter
ReplyDeleteGreat article! I have had problems with this for a long time
ReplyDeleteYou run a very good blog. Everything is very understandable. Good job!