The gform_export_fields filter allows you to customize the field selection list for entry exports in Gravity Forms. It can be used to add, modify, or remove fields from the export list.
Usage
To use the filter, add the following code in your theme’s functions.php
file:
add_filter('gform_export_fields', 'your_function_name');
Parameters
$form
(Form Object): The current form object.
More information
See Gravity Forms Docs: gform_export_fields
Examples
Add custom fields
Add two custom fields to the field selection list:
add_filter('gform_export_fields', 'add_fields', 10, 1); function add_fields($form) { array_push($form['fields'], array('id' => 'custom_field1', 'label' => __('Custom Field 1', 'gravityforms'))); array_push($form['fields'], array('id' => 'custom_field2', 'label' => __('Custom Field 2', 'gravityforms'))); return $form; }
Remove fields
Remove specific fields from the field selection list for form ID 3:
add_filter('gform_export_fields', function($form) { if ($form['id'] == 3) { $fields_to_remove = array( 'payment_amount', 'payment_date', 'payment_status', 'transaction_id', 'user_agent', 'ip', 'post_id' ); foreach ($form['fields'] as $key => $field) { $field_id = is_object($field) ? $field->id : $field['id']; if (in_array($field_id, $fields_to_remove)) { unset($form['fields'][$key]); } } } return $form; });
Remove advanced field inputs
Remove hidden name and address field inputs from the field selection list:
add_filter('gform_export_fields', function($form) { $types = array('name', 'address'); foreach ($form['fields'] as $key => $field) { if (is_object($field) && in_array($field->get_input_type(), $types)) { foreach ($field->inputs as $i => $input) { if (rgar($input, 'isHidden')) { unset($field->inputs[$i]); } } } } return $form; });
Single columns for multi-input fields
Follow this tutorial by Gravity Wiz to add a choice for each multi-input field, allowing the field to be exported as a single column.
Include Section Fields
Include Section type fields in the field selection list:
add_filter('gform_export_fields', 'restore_section_fields', 10); function restore_section_fields($form) { foreach ($form['fields'] as $key => $field) { if (is_object($field) && $field->type == 'section') { $new_field = array( 'id' => $field->id, 'label' => $field->label, 'description' => $field->description, ); $form['fields'][$key] = $new_field; } } return $form; }
Remember to use the gform_export_field_value
hook to include the field description in the csv file.