Last active
June 25, 2020 09:06
-
-
Save andrei-tofan/6debd7e3c46b2a69be13b7c1e006162f to your computer and use it in GitHub Desktop.
Ninja Forms JavaScript Hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var form_id = 3; | |
// listen to all ajax completed events | |
jQuery(document).ajaxComplete(function (event, jqXHR, ajaxOptions) { | |
// try to parse response | |
var data = JSON.parse(jqXHR.responseText || '{}'); | |
// check if the ajax request is for our form | |
if (data.data.form_id == form_id) { | |
var fields = data.data.fields || {}; | |
// search for email in fields | |
var email = Object.keys(fields).reduce(function (email, field) { | |
var element = fields[field]; | |
if (element.element_class == 'email-element' && !email) { | |
return element.value; | |
} | |
return email; | |
}, null); | |
// check if the email was found | |
if (email) { | |
console.log(email); | |
// send email to leadbi | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't seem to work anymore with version 3 as there is no AJAX event that I can see in the network console.