0

I want to create a custom newsletter subscription using Magento 1.9.1.0.

Currently, I have one newsletter subscription that captures emails and stores it in Newsletter -> Newsletter Subscribers.

I want to create another one that stores it in the same location. This time, when the users subscribe on the new one, it will popup a modal.

Is this possible or is there any other way around for this? Thank you.

EDIT: If possible, is it possible to execute/submit the subscription via Ajax? I think this would solve my problem but I don't know how to write it in Ajax.

1 Answer 1

0

I managed to make it work by using this code from here.

I tweaked the code to fit my current code structure. First, my form has an ID of newsletter-ajax.

Here's what I did with the JavaScript Ajax Code:

  1. Declare this variables var formId = 'newsletter-ajax'; var myForm = new VarienForm(formId, true); var postUrl = "/newsletter/subscriber/new";
  2. Create the ajax function function doAjax() { if (myForm.validator.validate()) { new Ajax.Updater( { success:'formSuccess' }, postUrl, { method:'post', asynchronous:true, evalScripts:false, onComplete:function(request, json) { Element.hide(formId); Element.show('formSuccess'); }, onLoading:function(request, json){ Element.show('formLoader'); }, parameters: $(formId).serialize(true), } ); } }

  3. Create the event observer new Event.observe(formId, 'submit', function(e){ e.stop(); doAjax(); });

Do note that these codes should be inside a <script> tag (pretty sure everyone knows this).

Read more about how I did it at twincreations from the link above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.