Title: JavaScript form events data null
Last modified: May 19, 2022

---

# JavaScript form events data null

 *  Resolved [Margot Keller](https://wordpress.org/support/users/margotk/)
 * (@margotk)
 * [4 years ago](https://wordpress.org/support/topic/javascript-form-events-data-null/)
 * Hello there,
 * I use JavaScript form events, but I would like to do an action if the form succeed
   OR if the user is already subscribed.
    I didn’t get where I can have the status
   of the response in order to differentiate it.
 * I’ve tried different events and this is what I get:
 * **submitted**
    if already subscribed: data = null if new: data = null **success**
   Nothing return if already subscribed
 * **subscribed**
    Nothing return if already subscribed
 * This is the code:
 *     ```
       mc4wp.forms.on('submitted', function(form, data) {
          console.log(data);
       });
       ```
   
 * Precision: it’s not a form used to update. (It’s a simple newsletter subscription
   form)
 * I don’t need specially the content of data, I just need a criterion to differentiate“
   successful/already registered” from “potential errors”.
 * Thank you for your help !
    -  This topic was modified 4 years ago by [Margot Keller](https://wordpress.org/support/users/margotk/).
    -  This topic was modified 4 years ago by [Margot Keller](https://wordpress.org/support/users/margotk/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Contributor [Lap](https://wordpress.org/support/users/lapzor/)
 * (@lapzor)
 * [4 years ago](https://wordpress.org/support/topic/javascript-form-events-data-null/#post-15663304)
 * Please look at this snippet:
 *     ```
       <script type="text/javascript">
       mc4wp.forms.on('subscribed', function(form, data, updated) {
         if(!updated) {
           console.log('This is new subscriber');
         } else {
           console.log('This is an updated subscriber');
         }
       })
       </script>
       ```
   
 * [https://www.mc4wp.com/kb/javascript-form-events/](https://www.mc4wp.com/kb/javascript-form-events/)
 * Hope that helps. If you have any questions, please let me know!
 *  Thread Starter [Margot Keller](https://wordpress.org/support/users/margotk/)
 * (@margotk)
 * [4 years ago](https://wordpress.org/support/topic/javascript-form-events-data-null/#post-15663518)
 * Hello,
 * thanks for the reply,
 * I tested this snippet, and if the user is already subscribed, It does not fit
   in the condition at all.
    If it’s a new subscriber, yes it log “This is new subscriber”
   well.
 * It seems that the event “subscribed” is not happen if the user is already subscribed.
 *  Plugin Contributor [Lap](https://wordpress.org/support/users/lapzor/)
 * (@lapzor)
 * [4 years ago](https://wordpress.org/support/topic/javascript-form-events-data-null/#post-15663560)
 * So “update subscriber” is set to No in the form’s settings?
    One possible solution
   could be to turn update to Yes. It won’t overwrite fields that aren’t in this
   particular form.
 * Otherwise, if updating subscribers is not an option for your case, you would 
   have to look for the ‘success’ event, that will fire whenever the form is submitted
   without errors, and separately look for the ‘subscribed’ event. In the case of
   existing subscriber only the success event will trigger, otherwise BOTH will 
   trigger.
 * There is no way to check from within the success event if it resulted in subscribing
   or not.
 * Kind regards,
 *  Thread Starter [Margot Keller](https://wordpress.org/support/users/margotk/)
 * (@margotk)
 * [4 years ago](https://wordpress.org/support/topic/javascript-form-events-data-null/#post-15663599)
 * “update subscriber” is now set to Yes, and it works !
 * This solution is fine with me, and the other one proposed seems fine too.
 * Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘JavaScript form events data null’ is closed to new replies.

 * ![](https://ps.w.org/mailchimp-for-wp/assets/icon-256x256.png?rev=1224577)
 * [MC4WP: Mailchimp for WordPress](https://wordpress.org/plugins/mailchimp-for-wp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mailchimp-for-wp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mailchimp-for-wp/)
 * [Active Topics](https://wordpress.org/support/plugin/mailchimp-for-wp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mailchimp-for-wp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mailchimp-for-wp/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Margot Keller](https://wordpress.org/support/users/margotk/)
 * Last activity: [4 years ago](https://wordpress.org/support/topic/javascript-form-events-data-null/#post-15663599)
 * Status: resolved