bookmark_bordergform_export_fields

Description

Use this filter to add custom columns to the entry export. The new fields show in the field selection list. Use this filter in conjunction with the filter gform_export_field_value.

Usage

add_filter( 'gform_export_fields', 'your_function_name' );

Parameters

  • $form

    The current form.

Examples

1. Add custom field

This example adds 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;
}

2. Remove fields

This example shows how you can remove fields from the field selection list.

add_filter( 'gform_export_fields', function ( $form ) {
    // only limit the fields available for export form form ID 3
    if ( $form['id'] == 3 ) {
        // array of field IDs I never want to see on the export page
        $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 ] );
            }
        }
    }

    // always return the form
    return $form;
} );

3. Remove advanced field inputs

This example shows how you can 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;
} );

4. Single columns for multi-input fields

This tutorial (by Gravity Wiz) adds a choice for each multi-input field allowing the field to be exported as a single column.

5. Include Section Fields

This example shows how you can make Section type fields available for selection, you’ll also need to use the gform_export_field_value hook to include the field description in the csv file.

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;
}

Placement

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

Source Code

This filter is located in GFExport::add_default_export_fields() in export.php