function submitForm(action, uploadType, profileObj) {
  try {
    showLoader();
    var frmData = {};
    var isValid = true;
    var dataForTracking = {};
    frmData["applyType"] = applyType;
    frmData["jobTitle"] = jobTitle;
    frmData["jobSeqNo"] = jobSeqNo;
    frmData["flowNumber"] = g_flowNumber;
    frmData["utm_source"] = utm_source;
    var referrerToken = getCookie("referrerToken");
    if (referrerToken && referrerToken.length > 1) {
        if( profileData && profileData.referrerDetail && 
        jobId === profileData.referrerDetail.jobId ){
          frmData["ref_source"] = (profileData.referrerDetail.referralSource == "copy-link") ? "-1" : profileData.referrerDetail.referralSource;
          frmData["ref_candidateid"] = profileData.referrerDetail.referrerAtsCandidateID;
        }
        
      frmData["referrerToken"] = referrerToken;
    }
    var loginType = $("input[name='loginType']").val();
    if (loginType == "login" || loginType == "registration") {
       username = $("input[name='email']").val();
      if (loginType == "registration") {
        $("#ddlLanguage").val(langMap[phApp.locale]);
      } else {
        frmData["submitApplyDataMap"] = {};
      }
      sessionStorage.setItem(
        jobSeqNo,
        JSON.stringify({
          sessType: "loggedin",
        })
      );
    }else{
        var sesObj = JSON.parse(sessionStorage.getItem(jobSeqNo));
        if( sesObj && sesObj.sessType === "guest" ){
          if ($("input[name='email']").length > 0) {
            username = $("input[name='email']").val();
          }else if (profileData != undefined && profileData != null) {
            username = profileData.email ? profileData.email : profileData.username;
          }
        }else if(profileData != undefined && profileData != null){
          username = profileData.email ? profileData.email : profileData.username;
        }
    }
    var frmArr = $("form").find(":hidden").serializeArray();
    frmArr.forEach(function (frm) {
      frmData[frm.name] = frm.value;
    });
    $("form").find("input:disabled").each(function () {       
       frmData[this.name] = this.value;
    });
    if (action === "guest") {
      frmData["stepNum"] = "1";
      frmData["loginType"] = "guest";
      sessionStorage.setItem(
        jobSeqNo,
        JSON.stringify({
          sessType: "guest",
        })
      );
    } else if (action === "fileUpload") {
      var fileObj = resumeSpec[uploadType];
      if (uploadType == "additionalAttachments") {
        fileObj = fileObj[fileObj.length - 1];
      }
      if (profileObj) {
        frmData["stepNum"] = "11";
        frmData["socialProfileObj"] = profileObj;
        frmData["socialProviderId"] = fileObj.socialProviderId;
      } else {
        frmData["stepNum"] = "4";
        frmData["postBackID"] = fileObj.uniqueId;
        frmData["uploadedfile_publicURL"] = fileObj.publicURL;
        frmData["uploadedfile_fileName"] = fileObj.fileName;
      }
    } else if (action !== "back") {
      if (action == "submit") {
        frmData["stepNum"] = "3";
      } else {
        frmData["stepNum"] = g_stepNum;
      }
      frmArr = $("form").find(":visible").not(".jsq").serializeArray();
      frmArr.forEach(function (frm) {
        frmData[frm.name] = frm.value;
      });
      if (frmData.countryCode) {
        frmData["userCountry_displayName"] = $(
          "#countryCode option:selected"
        ).text();
      }
      frmData["parsedUserCountry_displayName"] = $(
        "#parsedUserCountry_displayName"
      ).val();
      if ($(".question-section").length > 0) {
        frmArr = $(".question-section")
          .find(":visible")
          .not(":checkbox")
          .serializeArray();
        frmArr.forEach(function (frm) {
          frmData[frm.name] = frm.value;
        });
        frmArr = $(".question-section")
          .find(":visible:checkbox")
          .serializeArray();
        frmArr.forEach(function (frm) {
          if (frmData[frm.name]) {
            var listVal = frmData[frm.name];
            listVal.push(frm.value);
            frmData[frm.name] = listVal;
          } else {
            frmData[frm.name] = [frm.value];
          }
        });
      }
      $("div.grand-parent").each(function () {
        frmData = prepareCloneData(frmData, this);
      });
      if ($(".options-block").length > 0) {
        frmData["fileObj"] = resumeSpec;
        frmData["resumeSource"] = resumePlugObj.getResumeSource();
      }
      isValid = validateForm(formid);
      if(isValid){
        replacehtmltags();
      }
    } else {
      frmData["stepNum"] = g_stepNum;
    }
    // if current page is the 1st step make liginType as guest. now hard coded
    if (externalSource) {
      if (externalSource != undefined && !externalSource.isNaN) {
        if (externalSource == 1){
          frmData.submitApplyDataMap = {};
          frmData["loginType"] = "guestlogin";
        }
        if (action == "back") {
          frmData["externalSource"] = (parseInt(externalSource) - 1).toString();
        } else {
          frmData["externalSource"] = (parseInt(externalSource) + 1).toString();
        }
      }
    }
 
    if (action !== "guest") frmData["username"] = username.toLowerCase();
    if (action && action == "fileUpload"){
          frmData["eventData"] = null;
    }else{
          frmData["eventData"] = prepareKafkaData(
            dataForTracking,
            g_stepNum,
            true
          );
    }
    if (isValid) {
      if (
        profileData == undefined ||
        profileData == null ||
        profileData.submitApplyDataMap == undefined ||
        profileData.submitApplyDataMap == null
      ) {
        var submitApplyData = {};
      } else {
        submitApplyData = profileData.submitApplyDataMap;
      }
      if (
        action !== "back" &&
        $(".csod-action").length > 0 &&
        action !== "fileUpload"
      ) {
        var submitedData = prepareATSRequest(submitApplyData, frmData);
        frmData["submitApplyDataMap"] = submitedData;
      }
      if (action == "submit") {
        frmData["submitApplyData"] = $.map(
          frmData["submitApplyDataMap"],
          function (value, index) {
            return value;
          }
        );
        delete frmData.submitApplyDataMap;
      }
      var obj = {
        ddoKey: "applySubmit",
        formData: frmData,
      };
      var disabled = $("#" + formid)
        .find("form:input:disabled")
        .removeAttr("disabled");
      $.ajax({
        type: "POST",
        cache: false,
        contentType: "application/json; charset=utf-8",
        url: phApp.baseDomain + "/applySubmit",
        data: JSON.stringify(obj),
        dataType: "json",
        beforeSend: function () {
          if (!isRussComplEnabled) {
            if (action == "back") {
              raiseApplyClickEvent(g_stepNum, "back");
            } else if (action == "guest") {
              raiseApplyClickEvent(g_stepNum, null, getEventName("guest"));
            } else if (action !== "fileUpload") {
              raiseApplyClickEvent(g_stepNum, "submit");
            }
          }
        },
        success: function (response) {
          var response = eval(response).applySubmit.response;
          if(response.statusCode === "APPLY_SERVER_SIDE_VALIDATION_ERROR") {
              $("#errorMessage").html(response.statusMessage);
              alert(response.statusMessage);
              closeLoader();
              return true;  
          }
          //if (action != "fileUpload") {
            var stepForm = response.step;
            profileData = response.profileData;
            g_stepNum = response.stepNum;
            g_flowNumber = response.flowNumber;
            handleApplyResponse(response, function () {
              if (response.status !== "success") {
                saveState();
                closeLoader();
              }
            }, action);
          //}
        },
        error: function (request, status, error) {
          closeLoader();
          console.log("error occured::" + error);
          $("#errorMessage").html($.i18n("apply.internal.server.error.mssg"));
        },
      });
      disabled.attr("disabled", "disabled");
      if (action !== "fileUpload") pageScrollTop();
    } else {
      closeLoader();
      validationScroll();
    }
  } catch (err) {
    closeLoader();
    console.log("error occured::" + err);
    $("#errorMessage").html($.i18n("apply.internal.server.error.mssg"));
  }
}
where in this function form is checked for right data