Introduction
The gform.adminUtils object provides utility functions commonly used in the WordPress admin. These utilities can help handle unsaved changes warnings and extract query parameters from the URL.
Methods
handleUnsavedChanges()
Attaches a warning message when users attempt to leave the page with unsaved changes. This helps prevent data loss in custom admin interfaces or settings panels.
Usage
gform.adminUtils.handleUnsavedChanges();
| Parameter | Type | Description |
|---|---|---|
| None | — | This function does not require any parameters. |
Examples
document.addEventListener('DOMContentLoaded', function () {
gform.adminUtils.handleUnsavedChanges();
});
getUrlParameter(name)
Retrieves the value of a specific query parameter from the current URL. Useful for conditionally loading scripts or behavior based on page context.
const formId = gform.adminUtils.getUrlParameter('id');
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the query parameter to retrieve. |
Returns
| Type | Description |
|---|---|
string|null | The value of the parameter if found, or null if not present. |
Examples
const page = gform.adminUtils.getUrlParameter('page');
if (page === 'gf_edit_forms') {
console.log('We are on the form editor page.');
}
Source Code
The gform.adminUtils object is defined in js/gforms_hooks.js