Using Gravity Forms ‘gform_input_masks’ PHP filter

The gform_input_masks filter allows you to modify the list of built-in input masks displayed in the Text Field input mask setting. This is useful for adding custom input masks that you plan to use repeatedly.

Usage

add_filter('gform_input_masks', 'add_mask');

Parameters

  • $masks (array): The current list of masks to be filtered, in the following format:
array(
    'US Phone' => '(999) 999-9999',
    'US Phone + Ext' => '(999) 999-9999? x99999',
    'Date' => '99/99/9999',
    'Tax ID' => '99-9999999',
    'SSN' => '999-99-9999',
    'Zip Code' => '99999',
    'Full Zip Code' => '99999?-9999'
);

More information

See Gravity Forms Docs: gform_input_masks

Examples

Add a new predefined mask for “Product Key”

This code adds a new predefined mask for “Product Key” to the list of built-in input masks.

add_filter('gform_input_masks', function($masks) {
    $masks['Product Key'] = 'a*-999-a999';
    return $masks;
});

Remove “US Phone” mask from the list

This code removes the “US Phone” mask from the list of built-in input masks.

add_filter('gform_input_masks', function($masks) {
    unset($masks['US Phone']);
    return $masks;
});

Modify the “Date” mask format

This code changes the “Date” mask format to “99-99-9999” in the list of built-in input masks.

add_filter('gform_input_masks', function($masks) {
    $masks['Date'] = '99-99-9999';
    return $masks;
});

Add a new custom mask for “ISBN”

This code adds a new custom mask for “ISBN” (International Standard Book Number) to the list of built-in input masks.

add_filter('gform_input_masks', function($masks) {
    $masks['ISBN'] = '999-9-99-999999-9';
    return $masks;
});

Add a new custom mask for “Canadian Postal Code”

This code adds a new custom mask for “Canadian Postal Code” to the list of built-in input masks.

add_filter('gform_input_masks', function($masks) {
    $masks['Canadian Postal Code'] = 'A9A 9A9';
    return $masks;
});

Note: You can place the code examples in the functions.php file of the active theme, a custom functions plugin, or a custom add-on.