Skip to content

Instantly share code, notes, and snippets.

@andrei-tofan
Last active June 25, 2020 09:06
Show Gist options
  • Save andrei-tofan/6debd7e3c46b2a69be13b7c1e006162f to your computer and use it in GitHub Desktop.
Save andrei-tofan/6debd7e3c46b2a69be13b7c1e006162f to your computer and use it in GitHub Desktop.
Ninja Forms JavaScript Hook
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
}
}
});
@eversionsystems
Copy link

This doesn't seem to work anymore with version 3 as there is no AJAX event that I can see in the network console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment