Hello @aklapwijk,
Thanks for the question.
Correct me if I am wrong: you’re looking for a place on the form editor in the admin view where you can add some JavaScript code that will fire when a user successfully subscribes to a mailing list. Does that sound right?
If that’s the case, unfortunately there is no support for that at the moment.
If you’re looking for a PHP- / WordPress-based action hook to attach to, then check out the process_form_submission.php page where we’ve included the actions yikes-mailchimp-after-submission, yikes-mailchimp-after-submission-$form_id, yikes-mailchimp-form-submission, and yikes-mailchimp-form-submission-$form_id.
I hope I helped; please respond with more questions if you have them.
Thanks,
Kevin.
Hi Kevin,
Thanks for your reply.
Sounds about right; I’m looking for a way to add some JavaScript code that will file when a user successfully subscribes. Not via the form editor in the admin view however, but rather in my IDE.
For now I guess I will just use .ajaxSuccess() and use the responseText to detect if the submission was successful.
Thanks,
Anne
-
This reply was modified 9 years, 6 months ago by
aklapwijk.
Hello Anne,
Now I understand what you’re trying to do; it can be accomplished as you said.
In the yikes-mc-ajax-form.js file (plugins/yikes-inc-easy-mailchimp-extender/public/js/yikes-mc-ajax-forms.js) you can add your custom code after line 91 ( if( response.success ) { ). You can use the JavaScript variables from the data object to get the information you need, like form_id and email address. However, as you probably know, this code would get wiped out during an update so keep that in mind.
Also, this will only trigger for MailChimp forms that are using the AJAX method. If any of them are going through PHP form submissions, the code would not fire. I would recommend using one of the PHP-/WordPress-based action hooks to achieve the same functionality as the AJAX.
I hope that helps; please let us know,
Kevin
Hi again Anne,
I just wanted to add that I’d recommend using the PHP-/WordPress-based action hooks instead of editing the JS file as this would allow you to put the code in a separate area from the plugin, and therefore you would not lose any code or analytics data during / after an update.
Kevin.
Hi Kevin,
Thanks for your help. I totally agree with you, it’s best to not edit the plugins code. I will use the PHP-/WordPress based action hooks as much as possible, however in some cases I would use JavaScript. For example when using AJAX, to change styling of some elements after a user successfully subscribes, without a page refresh. I would do this in a separate area from the plugin though.
Thanks,
Anne
Sounds great, Anne; let me know if you need any additional help.
Also, if you’re enjoying the plugin, consider leaving us a friendly review or rating; they make our day!
Cheers,
Kevin.