cancel
Showing results for 
Search instead for 
Did you mean: 

Show global messages of newsletter subscription in popup

SOLVED

Show global messages of newsletter subscription in popup

I wish to show newsletter subscription global messages(like Thank you for your subscription.etc.) in popup.When a user click on newsletter subscription the default global message should come in popup. Followed this approach both at app/design/frontend/theme/template/page/1column.phtml and app/design/frontend/theme/template/newsletter/subscribe.phtml

 

<script type=“text/javascript”>var message = '<?php echo strip_tags($this->getChildHtml('global_messages')) ?>';
if (message == $this->__('Thank you for your subscription')) alert("What  ever you want to display!");
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Show global messages of newsletter subscription in popup

Hi @bhagyashree11

 

If you wants to change message in popup only for newsletter follow the steps:

  • open the block file located in /var/www/html/magento/app/code/core/Mage/Core/Block/Messages.php
  • Find the function getGroupedHtml()
  • Find the code in function:
foreach ( $messages as $message ) {


$html.= '<' . $this->_messagesSecondLevelTagName . '>';
$html.= '<' . $this->_messagesContentWrapperTagName . '>';
$html.= ($this->_escapeMessageFlag) ? $this->escapeHtml($message->getText()) : $message->getText();
$html.= '</' . $this->_messagesContentWrapperTagName . '>';
$html.= '</' . $this->_messagesSecondLevelTagName . '>';

}

Replace with :

foreach ( $messages as $message ) {

			if($message->getText() == "Thank you for your subscription."){

			$html.= "<script>";
			$message = $message->getText();
			$html.= "alert('$message')";
			$html.= "</script>";

			}else{

		            $html.= '<' . $this->_messagesSecondLevelTagName . '>';
		            $html.= '<' . $this->_messagesContentWrapperTagName . '>';
		            $html.= ($this->_escapeMessageFlag) ? $this->escapeHtml($message->getText()) : $message->getText();
		            $html.= '</' . $this->_messagesContentWrapperTagName . '>';
		            $html.= '</' . $this->_messagesSecondLevelTagName . '>';
			}
                }

this will print the newsletter message into alert.

Note: For standard development create module and override this function into your block.

 

Let me know if it helps Smiley Happy

Let me know if it helps. You can raise a KUDOS if its really worth for you. Also if it solves your problem then please mark as SOLUTION.

View solution in original post

3 REPLIES 3

Re: Show global messages of newsletter subscription in popup

Hi @bhagyashree11

 

Please edit in above file app/design/frontend/base/default/template/core/messages.phtml. In this file you will see the $message->getText() function print the message in foreach loop here you can get direct message text . Please edit according to your need. In the above post you are doing wrong

$this->getChildHtml('global_messages')

this code print whole html file not only message text.

 

Let me know if it helps.

Let me know if it helps. You can raise a KUDOS if its really worth for you. Also if it solves your problem then please mark as SOLUTION.

Re: Show global messages of newsletter subscription in popup

Hello @htpvikas,

 

Thanks a lot Smiley Happy

Can you please tell me what I will edit in that file for showing newsletter succes/error messges in popup

Re: Show global messages of newsletter subscription in popup

Hi @bhagyashree11

 

If you wants to change message in popup only for newsletter follow the steps:

  • open the block file located in /var/www/html/magento/app/code/core/Mage/Core/Block/Messages.php
  • Find the function getGroupedHtml()
  • Find the code in function:
foreach ( $messages as $message ) {


$html.= '<' . $this->_messagesSecondLevelTagName . '>';
$html.= '<' . $this->_messagesContentWrapperTagName . '>';
$html.= ($this->_escapeMessageFlag) ? $this->escapeHtml($message->getText()) : $message->getText();
$html.= '</' . $this->_messagesContentWrapperTagName . '>';
$html.= '</' . $this->_messagesSecondLevelTagName . '>';

}

Replace with :

foreach ( $messages as $message ) {

			if($message->getText() == "Thank you for your subscription."){

			$html.= "<script>";
			$message = $message->getText();
			$html.= "alert('$message')";
			$html.= "</script>";

			}else{

		            $html.= '<' . $this->_messagesSecondLevelTagName . '>';
		            $html.= '<' . $this->_messagesContentWrapperTagName . '>';
		            $html.= ($this->_escapeMessageFlag) ? $this->escapeHtml($message->getText()) : $message->getText();
		            $html.= '</' . $this->_messagesContentWrapperTagName . '>';
		            $html.= '</' . $this->_messagesSecondLevelTagName . '>';
			}
                }

this will print the newsletter message into alert.

Note: For standard development create module and override this function into your block.

 

Let me know if it helps Smiley Happy

Let me know if it helps. You can raise a KUDOS if its really worth for you. Also if it solves your problem then please mark as SOLUTION.