Using Gravity Forms ‘gform_webhooks_request_data’ PHP filter

The gform_webhooks_request_data filter allows you to modify the webhook HTTP request data.

Usage

A generic example of using the filter for all forms:

add_filter('gform_webhooks_request_data', 'your_function_name', 10, 4);

To target a specific form, append the form ID to the hook name:

add_filter('gform_webhooks_request_data_7', 'your_function_name', 10, 4);

Parameters

  • $request_data (array): HTTP request data.
  • $feed (Feed Object): The current feed object.
  • $entry (Entry Object): The current entry object.
  • $form (Form Object): The current form object.

More information

See Gravity Forms Docs: gform_webhooks_request_data

Examples

Add a new field

This example adds a new field with a value ‘Tester McTesty’:

add_filter('gform_webhooks_request_data', 'modify_data', 10, 4);

function modify_data($request_data, $feed, $entry, $form) {
    $request_data[1] = 'Tester McTesty';
    return $request_data;
}

Modify the field keys

Replace the period in the input IDs with an underscore for webhooks to Automate.io:

add_filter('gform_webhooks_request_data', function($request_data, $feed) {
    if (rgars($feed, 'meta/requestBodyType') === 'all_fields' && strpos(rgars($feed, 'meta/requestURL'), 'automate.io') !== false) {
        foreach ($request_data as $key => $value) {
            if (is_numeric($key)) {
                $request_data['field ' . str_replace('.', '_', $key)] = $value;
                unset($request_data[$key]);
            }
        }
    }
    return $request_data;
}, 10, 2);

Modify field values for the Events Calendar plugin

Change string field values to booleans as required by the Events Calendar plugin:

add_filter('gform_webhooks_request_data', function($request_data, $feed) {
    $request_url = rgars($feed, 'meta/requestURL');
    if (strpos($request_url, 'tribe/events/') !== false) {
        $requires_bool_values = array('all_day', 'show_map', 'show_map_link', 'hide_from_listings', 'sticky', 'featured');
        foreach ($request_data as $key => $value) {
            if (in_array($key, $requires_bool_values)) {
                $request_data[$key] = (bool)$value;
            }
        }
    }
    return $request_data;
}, 10, 2);

Remove empty values

Remove empty fields from the request data when the “all fields” choice is selected for the request body setting:

add_filter('gform_webhooks_request_data', function($request_data, $feed) {
    if (rgars($feed, 'meta/requestBodyType') === 'all_fields') {
        foreach ($request_data as $key => $value) {
            if (empty($value)) {
                unset($request_data[$key]);
            }
        }
    }
    return $request_data;
}, 10, 2);