Skip to content

Instantly share code, notes, and snippets.

@leadbi
Forked from andrei-tofan/ninja-forms.js
Created May 5, 2017 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leadbi/3d55e9d3172aa51cc37aa7a1bb68c336 to your computer and use it in GitHub Desktop.
Save leadbi/3d55e9d3172aa51cc37aa7a1bb68c336 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
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment