Using Gravity Forms ‘gform_export_field_value’ PHP filter

The gform_export_field_value filter allows you to modify the field value before it is included in the Gravity Forms CSV export. This filter can be used together with the gform_export_fields filter to include custom columns in the export.

Usage

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

Parameters

  • $value (string): The value of the field being exported.
  • $form_id (integer): The ID of the current form.
  • $field_id (integer): The ID of the current field.
  • $entry (Entry Object): The current entry.

More information

See Gravity Forms Docs: gform_export_field_value

Examples

Set export value for custom fields

This example sets the values for two custom fields that were added to the export. The custom fields are named “custom_field1” and “custom_field2”.

add_filter('gform_export_field_value', 'set_export_values', 10, 4);

function set_export_values($value, $form_id, $field_id, $entry) {
    switch($field_id) {
        case 'custom_field1':
            $value = 'valueforcustomfield1';
            break;
        case 'custom_field2':
            $value = 'valueforcustomfield2';
            break;
    }
    return $value;
}

Use choice text instead of values

add_filter('gform_export_field_value', 'export_choice_text', 10, 4);

function export_choice_text($value, $form_id, $field_id, $entry) {
    $field = GFAPI::get_field($form_id, $field_id);
    return is_object($field) && is_array($field->choices) ? $field->get_value_export($entry, $field_id, true) : $value;
}

Decode special characters

This example shows how you can decode special characters such as the ampersand which may have been encoded during field value sanitization.

add_filter('gform_export_field_value', 'decode_export_values');

function decode_export_values($value) {
    return htmlspecialchars_decode($value);
}

Format date field value

add_filter('gform_export_field_value', 'format_date', 10, 4);

function format_date($value, $form_id, $field_id, $entry) {
    $field = GFAPI::get_field($form_id, $field_id);
    return is_object($field) && $field->type == 'date' ? GFCommon::date_display($value, $field->dateFormat) : $value;
}

Use display name instead of user id

add_filter('gform_export_field_value', 'export_user_display_name', 10, 4);

function export_user_display_name($value, $form_id, $field_id, $entry) {
    if ($field_id == 'created_by') {
        $user  = get_user_by('id', $value);
        return is_object($user) ? $user->display_name : $value;
    }
    return $value;
}