Contact
'+jsonResp.htmldatatodisplay+'
').fadeOut('fast');
}
},
beforeSerialize: function($form, options) {
// using autorize.net
var amounts = $('input[name="donation_amount"]');
var amount = 0;
var item = "Website Donation";
var repeatPayment = $('#donation_repeat_payment').prop('checked');
var fund_options = $('input[name="donation_selected"]');
if(fund_options.length !== 0) {
$.each(fund_options, function(index, option) {
if(option.type == 'radio' && option.checked) {
item = option.value;
} else if(option.type == 'select-one') {
if( $(option).val() != "0" && $(option).val() != "No fund specified" ) {
item = $(option).val();
}
}
});
}
if(amounts.length !== 0) {
$.each(amounts, function(index, val) {
if( $(val).prop('checked') && $(val).val() != 'Other') {
amount_raw = $(val).val();
amount = amount_raw.replace(/\D/g, '');
} else if( $(val).prop('checked') && $(val).val() == 'Other' ){
amount_raw = $('#donation_amount_other_amount_entered').val();
amount = amount_raw.replace(/\D/g, '');
}
});
$('input[type="hidden"][name="payment_amount"]').val(amount);
$('input[type="hidden"][name="payment_item_name"]').val(item);
$('input[type="hidden"][name="payment_recurring"]').val(repeatPayment);
}
}
};
// submit our form
$('#contact').ajaxForm(options);
// handle save for later button action
$('#save_later').click(function(evt) {
$('#contact').append('');
var save_later_options = {
url: saveURL+'/formID/'+formID,
type: 'POST',
success : function(resp) {
$('input#save_for_later').remove();
if (typeof resp === 'string') {
var jsonResp = $.parseJSON(resp);
} else {
var jsonResp = resp;
}
var msg = "";
var success = false;
console.log(typeof jsonResp);
if(typeof jsonResp === "Array") {
$.each(jsonResp, function(index, item) {
if(item.success) {
success = true;
}
msg += item.message + ''; }); } else { if(jsonResp.hasOwnProperty('success')) { success = jsonResp.success; } else { success = false; } if(jsonResp.hasOwnProperty('htmldatatodisplay')) { $('form#'+formSelector).after('
'+jsonResp.htmldatatodisplay+'
').fadeOut('fast');
}
}
if(success && msg !== "") {
$('.validation_response').removeClass('danger bg-danger').addClass('success bg-success').html(''+msg+'
'); $(window).scrollTop(0); $('#'+formSelector).fadeOut('slow'); $('input[type!="checkbox"],textarea').prop('required', 'true'); } else if(msg !== "") { // success is false - show err msg to the user $('.validation_response').removeClass('success bg-success').addClass('danger bg-danger').html(''+msg+'
'); } } }; $('input,textarea').removeProp('required'); $('#contact').ajaxForm(save_later_options); }); $('#submit').click(function(evt) { $('input#save_for_later').remove(); }); });