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.
Name | Type | Description |
---|---|---|
SUBMISSION_METHOD_AJAX | string | Represents the “ajax” submission method. |
SUBMISSION_METHOD_IFRAME | string | Represents the “iframe” submission method. |
SUBMISSION_METHOD_POSTBACK | string | Represents the “postback” submission method. |
SUBMISSION_TYPE_NEXT | string | Used when moving to the next page in a multi-page form. |
SUBMISSION_TYPE_PREVIOUS | string | Used when moving to the previous page in a multi-page form. |
SUBMISSION_TYPE_SAVE_AND_CONTINUE | string | Used when saving a form to continue later. |
SUBMISSION_TYPE_SEND_LINK | string | Used when sending the save and continue link. |
SUBMISSION_TYPE_SUBMIT | string | Used for the final form submission. |
ajax | object | Contains internal AJAX submission utilities such as submitFormAjax and displayConfirmation . |
getSubmissionMethod(form) | function | Returns the method used to submit the form (e.g., ajax , iframe ). |
handleButtonClick(event) | function | Handles the click event for form buttons. |
lockSubmission(form) | function | Prevents duplicate submissions for a specific form. |
removeSpinner(form) | function | Removes the loading spinner from the submit button. |
submitForm(form, type, method) | function | Submits the form using the specified type and method. |
unlockSubmission(form) | function | Unlocks 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));
}