I have a js file that creates a form to collect clients contact info. When the form is submitted it sends a url string to the database. However the string needs to include a token and password to login to the database. So i need to somehow hide the token and password in a php file and add it to the string when the client hits submit. so far ive been able to get the data from a php file using .get or .ajax, but the js file already uses an .ajax request and i'm not sure how to combine them together. Any ideas? Thank you!
function initPopup() {
// open on load
if (xanadu_settings['show_popup'] == 'open') {
openXanadu();
}
// open on mouse out
else {
$('html > body').mouseleave(function() {
if (!popup_visible) {
openXanadu();
}
});
}
}
// This gets the login string i need to add to the form subit string below
var dataString = 'login';
$.ajax({
type: 'GET',
url: "login.php",
data: {data : dataString},
success: function(data) {
returnedvalue = data;
console.log(data);
}
});
$("#xanadu_wrapper form").validate({
rules: {
name: "required",
email: {
required: true,
email: true
}
},
messages: {
name: "Please specify your name",
email: {
required: "We need your email address to contact you",
email: "Your email address must be valid"
}
},
submitHandler: function(form, data) {
var report_url = "http://myLinkToTheAPI";
var submit_data = {
// token: $(form).find('input.token').val(),
// pass: $(form).find('input.pass').val(),
campaignId: $(form).find('input.campaignId').val(),
ipAddress: $(form).find('input#ipAddress').val(),
source: $(form).find('input.source').val(),
name: $(form).find('input.name').val(),
email: $(form).find('input.email').val(),
phone: $(form).find('input.phone').val(),
}
var form_submitted = false;
var submit_data = $(form).serialize();
$.ajax({
type: 'GET',
url: report_url,
data: submit_data,
complete: function() {
if ( ($(form).attr('action') != '') && (form_submitted == false) ) {
$(form)[0].submit();
form_submitted = true;
}
$(form).find('input, button').attr('disabled', '');
//Thank you! We will contact you shortly.
$(form).after('<p class="success-alert">' + xanadu_settings['success_message'] + '</p>');
$(form).next('.success-alert').fadeIn();
console.log(form);
console.log(form_submitted);
if (xanadu_settings['prevent_after_submission'] == 'true') {
setBlockCookie();
}
}
});
setTimeout(function(){
if ( ($(form).attr('action') != '') && (form_submitted == false) ) {
$(form)[0].submit();
form_submitted = true;
}
}, 500);
}
});