gform.config

Introduction

The gform.config object provides utility functions for retrieving, updating, and validating forms configuration settings in JavaScript. It includes methods for working with both local and AJAX loaded configuration data.

Methods

MethodDescription
getConfigRetrieves a value from a specific configuration group.
updateConfigUpdates or merges new values into an existing configuration group.
getFormConfigRetrieves a value from a form-specific configuration object.
getConfigViaAjaxFetches a configuration value dynamically using AJAX.
isValidChecks whether a value is considered valid (not null, undefined, or empty).
cleanPathNormalizes a path by removing extra slashes and whitespace.

getConfig()

Usage

const ajaxUrl = gform.config.getConfig('general', 'ajaxurl');

Parameters

ParameterTypeDescription
groupstringThe configuration group name.
keystringThe specific key to retrieve within the group.

Examples

const ajaxUrl = gform.config.getConfig('general', 'ajaxurl');
console.log('AJAX URL:', ajaxUrl);

updateConfig()

Usage

gform.config.updateConfig('general', {
    customSetting: 'enabled'
});

Parameters

ParameterTypeDescription
groupstringThe name of the configuration group to update.
newConfigobjectAn object containing key-value pairs to merge into the group.

Examples

gform.config.updateConfig('general', {
    theme: 'dark',
    isEnabled: true
});

getFormConfig()

Usage

const isActive = gform.config.getFormConfig(1, 'is_active');

Parameters

ParameterTypeDescription
formIdnumberThe ID of the form.
keystringThe configuration key to retrieve.

Examples

const title = gform.config.getFormConfig(3, 'title');
console.log('Form Title:', title);

getConfigViaAjax()

Usage

gform.config.getConfigViaAjax('custom_group', 'setting_key')
    .then(value => {
        console.log('Config Value:', value);
    });

Parameters

ParameterTypeDescription
groupstringThe configuration group to query.
keystringThe configuration key to retrieve.

Examples

gform.config.getConfigViaAjax('form_settings', 'custom_label')
    .then(label => {
        if (label) {
            console.log('Label loaded via AJAX:', label);
        }
    });

isValid()

Usage

const path = gform.config.cleanPath('/forms//123 /settings/');

Parameters

ParameterTypeDescription
valueanyThe value to validate.

Example

const value = gform.config.getConfig('custom', 'mode');
if (gform.config.isValid(value)) {
    console.log('Mode is set:', value);
}

cleanPath()

Usage

const path = gform.config.cleanPath('/forms//123 /settings/');

Parameters

ParameterTypeDescription
pathstringThe path string to clean and normalize.

Examples

const cleaned = gform.config.cleanPath(' /forms//5/settings ');
console.log('Cleaned Path:', cleaned); // Output: /forms/5/settings

Source Code

The gform.config object is defined in js/gforms_hooks.js