gform.submission

Introduction

The gform.submission object provides functions for managing form submissions with JavaScript. It includes methods for submitting a form, detecting the submission method, and preventing duplicate submissions.

This can be useful when you need to submit a form programmatically, without relying on the standard submit button.

NameTypeDescription
SUBMISSION_METHOD_AJAXstringRepresents the “ajax” submission method.
SUBMISSION_METHOD_IFRAMEstringRepresents the “iframe” submission method.
SUBMISSION_METHOD_POSTBACKstringRepresents the “postback” submission method.
SUBMISSION_TYPE_NEXTstringUsed when moving to the next page in a multi-page form.
SUBMISSION_TYPE_PREVIOUSstringUsed when moving to the previous page in a multi-page form.
SUBMISSION_TYPE_SAVE_AND_CONTINUEstringUsed when saving a form to continue later.
SUBMISSION_TYPE_SEND_LINKstringUsed when sending the save and continue link.
SUBMISSION_TYPE_SUBMITstringUsed for the final form submission.
ajaxobjectContains internal AJAX submission utilities such as submitFormAjax and displayConfirmation.
getSubmissionMethod(form)functionReturns the method used to submit the form (e.g., ajax, iframe).
handleButtonClick(event)functionHandles the click event for form buttons.
lockSubmission(form)functionPrevents duplicate submissions for a specific form.
removeSpinner(form)functionRemoves the loading spinner from the submit button.
submitForm(form, type, method)functionSubmits the form using the specified type and method.
unlockSubmission(form)functionUnlocks the form, allowing it to be submitted again.

Examples

Submitting a Form Programmatically

The example below shows how to create a helper function that submits a Gravity Form using the gform.submission API. The function accepts a form ID and handles validation and locking to avoid multiple submissions.

const submitForm = async (formId) => {
	if (!window?.gform?.submission?.submitForm) {
		return;
	}

	const form = document.getElementById(`gform_${formId}`);
	if (!form) {
		return;
	}

	const submission = window.gform.submission;
	if (!submission.lockSubmission(form)) {
		return;
	}

	await submission.submitForm(form, submission.SUBMISSION_TYPE_SUBMIT, submission.getSubmissionMethod(form));
}