You can handle the submit() event, which will occur only for your form submission.
Within that event, set your flag variable formHasChanged
to false to allow the unload to proceed. Also, just a suggestion, but since the purpose of that flag variable will have changed, so you may want to rename it something like 'warnBeforeUnload'
$(document).submit(function(){
warnBeforeUnload = false;
});