简体   繁体   中英

magento newsletter success message popup

I want to create a pop up message box that showed after user subscribing the newsletter

"your subscription have been confirmed [ok]"

it must be in javascript or jquery cause i want to modifying it in magento front end area only

it's similar like this post Magento newsletter succeess message in pop up but it's end up with no right answer and dead link

another info :My Magento ver. 1.14.1.0

I have code a little bit and put it in the subscribe.phtml but it wont work

<script type="text/javascript">
    var formdata = {'email': jQuery('input[name=email]').val()};
jQuery(document).ready(function() {

  jQuery('.btn-subs').click(function(){
    jQuery.ajax({
        method: "POST",
        url: "<?php echo Mage::getBaseUrl() ?>newsletter/subscriber/new/",
        data: formdata,
        datatype: 'json'
    })
    .success(function( data ) {
      alert( "Your Subscription has been confirmed" );
    })
    .error(function(data){
        alert(data);
        console.log(data);
    })
  });
});
</script>

Magento's builtin notification system is quite well-built and explained extensively by Inchoo here: http://inchoo.net/magento/magento-frontend/utilizing-magento-notification-system/

I'm kind of guessing that this is not exactly what you are looking for, since you state explicitly that it has to be done with javascript or with jquery. Have you realised that it is possible for a magento controller action to basically stay on the same page but add a notification after subscribing someone to a newsletter page?

This ( https://magento.stackexchange.com/questions/5063/reliable-way-to-redirect-to-last-page/5086 ) post helped me achieve to get a notification on a page with no redirect to a different page, just a reload of that same page.

If you really insist on only using js/jquery, my instinct is that a simple alert would suffice. This gives you by default only an 'ok' button, but i myself don't see the need for a 'cancel' button after an action has already been completed, unless this will undo the subscription to the newsletter i guess.

If this is not the case, could you give more information as to what you are trying to achieve and why it is important to use js/jquery only?

kind regards,

Tom

You can post to the controller asynchronously (AJAX), but it will not give you anything meaningful to verify success with by default.

What you would need to do is extend newsletter/subscriber/new (don't update the core file, any update will wipe your changes out.)

This could be helpful: http://inchoo.net/dev-talk/how-to-extend-magento-core-controller/

Basically, what you want to do is create a new controller action, that does almost everything the existing controller does, but instead of redirecting when its done, it should echo data for your front-end to parse in the ajax response. Also, you will want to remove the session success messages that are normally added. (They'd show up on next page load.)

So model your new controller after the existing one:

app/code/core/Mage/Newsletter/controllers/SubscriberController.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM