// James Doughty // Script for fading user form in and out // 29 Sept 2015 $(document).ready(function(){ var formEditUser = $('#formEditUser') editUser = $('#pnlEditUser'), displayUser = $('#pnlViewUser'), btnEditUser = $('#btnEditUser'), btnEditUserSave = $('#btnEditUserSave'), btnEditUserCancel = $('#btnEditUserCancel'), alertSuccessSaved = $('#alertSuccessSaved'), alertUpdateFailed = $('#alertUpdateFailed'); //-----------DIV SHOW HIDE------------------------------- btnEditUser.click(function() { alertSuccessSaved.hide(); // turn off messages alertUpdateFailed.hide(); // turn off messages displayUser.fadeOut(1000, function() { editUser.fadeIn(1000, function() { }); }); }); btnEditUserCancel.click(function() { editUser.fadeOut(1000, function() { displayUser.fadeIn(1000, function() { }); }); }); //------- DIV FORM SUBMIT -------------------------------- formEditUser.submit(function(event) { $('.help-block').remove(); // remove the error text $('.form-group').removeClass('has-error'); // remove the error class var formData = { 'contact_number' : $('input[name=contact_number]').val(), 'first_name' : $('input[name=first_name]').val(), 'last_name' : $('input[name=last_name]').val(), 'password' : $('input[name=password]').val(), 'practice' : $('input[name=practice]').val(), 'address' : $('input[name=address]').val(), 'email' : $('input[name=email]').val(), 'dob' : $('input[name=dob]').val() }; // process the form $.ajax({ type : 'POST', // define the type of HTTP verb we want to use (POST for our form) url : '/ajax_amend_details', // the url where we want to POST data : formData, // our data object dataType : 'json', // what type of data do we expect back from the server encode : true }) // using the done promise callback .done(function(data) { // log data to the console so we can see console.log(data); if ( ! data.success) { // handle errors for email field --------------- if (data.errors.email) { // add the error class to show red input: $('#email-group').addClass('has-error'); // add the actual error message under our input: $('#email-group').append('