Using Gravity Forms ‘gform_zapier_request_body’ PHP filter

The gform_zapier_request_body Gravity Forms PHP filter allows you to modify the request body sent to Zapier.

Usage

A generic example of how to use the filter:

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

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

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

Parameters

  • $body (array) – An associative array containing the request body that will be sent to Zapier.
  • $feed (Feed Object) – The feed object currently being processed.
  • $entry (Entry Object) – The entry object currently being processed.
  • $form (Form Object) – The form object currently being processed.

More information

See Gravity Forms Docs: gform_zapier_request_body

Examples

Change Date format

Change the date format of the “Entry Date” field in the request body:

add_filter('gform_zapier_request_body', 'change_date_format', 10, 4);

function change_date_format($body, $feed, $entry, $form) {
    $body['Entry Date'] = gmdate('Y-m-d', strtotime($entry['date_created']));
    return $body;
}

Send Score for Survey fields

Send the score for each survey field in the request body:

add_filter('gform_zapier_request_body', 'zapier_single_score_export', 10, 4);

function zapier_single_score_export($body, $feed, $entry, $form) {
    $survey_fields = GFAPI::get_fields_by_type($form, array('survey'));

    foreach ($survey_fields as $field) {
        $body_key = GFZapier::get_body_key($body, 'Survey Score: ' . $field->label);
        $body[$body_key] = gf_survey()->get_field_score($field, $entry);
    }

    return $body;
}

This code should be placed in the functions.php file of your active theme.

This filter was added in the Gravity Forms Zapier Add-On v3.1.1.

This filter is located in GFZapier::get_body() method in zapier.php.