-
-
Save leadbi/3d55e9d3172aa51cc37aa7a1bb68c336 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