$(function() { var successMsg = "Your accounts have been merged."; // Message shown on success. var failMsg = "Sorry, we were unable to action your request at this time. The server did not respond, please try again later or contact support."; // Message shown on fail. $("input,textarea").jqBootstrapValidation( { preventSubmit: true, submitSuccess: function($form, event) { event.preventDefault(); // prevent default submit behaviour var processorFile = "../forms/mergeAccounts.php"; var formData = {}; $form.find("input, textarea").each(function(e) // Loop over form objects build data object { var fieldData = $(this).val(); if($(this).is(':checkbox')) // Handle Checkboxes { fieldData = $(this).is(":checked"); } else if($(this).is(':radio')) // Handle Radios { fieldData = $(this).val()+' = '+$(this).is(":checked"); } formData[$(this).attr('id')] = fieldData; }); $.ajax({ url: processorFile, type: "POST", data: formData, cache: false, success: function(result) // Success { if(result == 'SUCCESS') { $form.append("
"+successMsg+"
"); $form.trigger("reset"); } else if(result == 'ERROR_INVALID_DATA') { $form.append("
Sorry, there is a problem with some of the data you have entered. Please correct and try again.
"); } else if(result == 'ERROR_INVALID_LOGIN') { $form.append("
Sorry, one of the email and password combinations entered does not match any account. Please correct the email and/or password and try again.
"); } else if(result == 'ERROR_CANNOT_COMPLETE') { $form.append("
Sorry, we were unable to complete the merge. Some of your assets may have been merged. Please contact support.
"); } else { // $form.append("
Sorry, we were unable to action your request at this time. The server returned an unknown reponse, please try again later or contact support.
"); } //$form.append("
"+successMsg+"
"); }, error: function() // Fail { $form.append("
"+failMsg+"
"); }, complete: function() // Clear { }, }); }, filter: function() // Handle hidden form elements { return $(this).is(":visible"); }, }); });