Sunday, 23 March 2014

Magento : Add “Subscribe to Newsletter” checkbox on Contact Form


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

/*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


      

5 comments:

  1. 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

    ReplyDelete
  2. This will be removed when you upgrade however. I suggest you app\code\local\Mage\Contacts\controllers\IndexController.php and edit that file

    ReplyDelete
    Replies
    1. I have update the post. Thank you so much for making it correct and more meaningful!!!! :)

      Delete
  3. i 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

    ReplyDelete

Thanks for your valuable comments.

Gmail: Download blocked file

Hi, today we are going to learn, how to download blocked file in gmail. Sometimes you see following message in gmail: and you can...