gform_export_field_value

gform_export_field_value

DescriptionUsageParametersExamples1. Set export value for custom fields2. Use choice text instead of values3. Decode special characters4. Format date field value5. Use display name instead of user id6. Format Number field value7. Remove new lines, tabs and carriage returns8. Export the secure file download URL9. Export customized Quiz field valuesPlacementSource Code

Description
Use this filter override the field value before it is included in the CSV export. This filter can be used in conjunction 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
Value of the field being exported.

$form_id integer
ID of the current form.

$field_id integer
ID of the current field.

$entry Entry Object
The current entry.

Examples
1. 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;
}

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

3. Decode special characters
The following 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 );
}

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

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

6. Format Number field value
add_filter( 'gform_export_field_value', 'format_number_field_value', 10, 4 );
function format_number_field_value( $value, $form_id, $field_id, $entry ) {
$field = GFAPI::get_field( $form_id, $field_id );
$include_thousands_sep = true;

return is_object( $field ) && $field->type == 'number' ? GFCommon::format_number( $value, $field->numberFormat, rgar( $entry, 'currency' ), $include_thousands_sep ) : $value;
}

7. Remove new lines, tabs and carriage returns
The following example shows how you can remove new lines, tabs and carriage returns before exporting the field value. Useful when importing CSV files in Excel.
add_filter( 'gform_export_field_value', 'decode_export_values' );
function decode_export_values( $value ) {
$value = str_replace(array("n", "t", "r"), '', $value);
return $value;
}

8. Export the secure file download URL
This example shows how you can replace the direct file URL with the secure file download URL.
add_filter( 'gform_export_field_value', function ( $value, $form_id, $field_id ) {
if ( ! empty( $value ) ) {
$field = GFAPI::get_field( $form_id, $field_id );
if ( $field && $field->get_input_type() === 'fileupload' ) {
$urls = explode( ' , ', $value );
foreach ( $urls as &$url ) {
$url = $field->get_download_url( $url, $force_download = true );
}
$value = implode( ' , ', $urls );
}
}

return $value;
}, 10, 3 );

9. Export customized Quiz field values
This example shows how to export values for Quiz fields. This is useful only when you have set custom values after using the gform_quiz_show_choice_values filter.
// Note that priority is set to 20 to run after the Quiz add-on. This is required.
add_filter( 'gform_export_field_value', 'export_quiz_value', 20, 4 );
function export_quiz_value( $value, $form_id, $field_id, $entry ) {
$field = GFAPI::get_field( $form_id, $field_id );

if ( $field->type == 'quiz'){
GFCommon::log_debug( __METHOD__ . '(): Running for field id: => ' . $field_id );
$value = rgar( $entry, $field_id );
GFCommon::log_debug( __METHOD__ . '(): Value from entry: => ' . $value );
}

return $value;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFExport::start_export() in export.php.

gform_field_choice_markup_pre_render

gform_field_choice_markup_pre_render

DescriptionUsageParametersExamples1. Add Custom Attribute2. Include Price for Product Fields3. Remove choice based on date4. Add CSS class to Multiselect choice5. Add inline list headingsPlacementSource Code

Description

This filter allows you to override the default choice markup used when rendering radio button, checkbox and drop down type fields.

Usage

To apply the filter to all radio, checkbox and drop down type fields on all forms you can do this:

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

To target a specific form append the form id to the hook name. (format: gform_field_choice_markup_pre_render_FORMID)

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

To target a specific field on a specific form append the form id and the field id to the hook name. (format: gform_field_choice_markup_pre_render_FORMID_FIELDID)

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

Parameters

$choice_markup stringThe string containing the choice markup to be filtered.

Checkbox


  • Radio


  • Select$choice arrayAn associative array containing the choice properties.

    array(
    'text' => 'First Choice',
    'value' => 'Item 1',
    'isSelected' => true,
    'price' => '10',
    )

    $field Field ObjectThe field currently being processed.$value stringThe value to be selected if the field is being populated.

    Examples

    1. Add Custom Attribute

    This example demonstrates how to add a custom attribute to the choice markup.

    add_filter( 'gform_field_choice_markup_pre_render_10', function ( $choice_markup, $choice, $field, $value ) {
    if ( $field->get_input_type() == 'radio' && rgar( $choice, 'text' ) == 'Second Choice' ) {
    return str_replace( "type='radio'", "type='radio' disabled", $choice_markup );
    }

    return $choice_markup;
    }, 10, 4 );

    2. Include Price for Product Fields

    This example shows how you can update the option markup to include the choice price for the drop down type Product field.

    add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field, $value ) {
    if ( $field->type == 'product' ) {
    $new_string = sprintf( '>%s - %s<', $choice['text'], GFCommon::to_money( $choice['price'] ) ); return str_replace( ">{$choice['text']}<", $new_string, $choice_markup ); } return $choice_markup; }, 10, 4 ); 3. Remove choice based on date This example shows how you can remove a choice from a specific field if the specified date has passed. add_filter( 'gform_field_choice_markup_pre_render_10_5', function ( $choice_markup, $choice ) { if ( rgar( $choice, 'value' ) == 'test' && time() >= strtotime( '2019-10-03' ) ) {
    return '';
    }

    return $choice_markup;
    }, 10, 2 );

    4. Add CSS class to Multiselect choice

    This example shows how you can add a CSS class to a Multiselect field choice labeled as 「Second Choice」.

    // Change 543 and 2 to your form id and field id respectively.
    add_filter( 'gform_field_choice_markup_pre_render_543_2', function ( $choice_markup, $choice, $field, $value ) {
    // Change Second Choice to the label of your choice.
    if ( $field->get_input_type() == 'multiselect' && rgar( $choice, 'text' ) == 'Second Choice' ) {
    // Change my_class to the CSS class name you want to use.
    return str_replace( "value=", "class='my_class' value=", $choice_markup );
    }

    return $choice_markup;
    }, 10, 4 );

    5. Add inline list headings

    This example shows how you can replace a choice with an inline heading, by prepending your option label with ###.

    add_filter( 'gform_field_choice_markup_pre_render', function( $choice_markup, $choice, $field, $value ) {
    if ( strpos( $choice['text'], '###' ) === 0 ) {
    $choice_markup = '

  • ' . ltrim( str_replace( '###', '', $choice['text'] ) ) . '
  • ';
    }

    return $choice_markup;
    }, 10, 4 );

    Placement

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

    Source Code

    This filter is located in the following methods:

    GFCommon::get_select_choices() in common.php – since 1.9.11.10GF_Field_Checkbox::get_checkbox_choices() in includes/fields/class-gf-field-checkbox.php – since 1.9.6GF_Field_Radio::get_radio_choices() in includes/fields/class-gf-field-radio.php – since 1.9.6

    gform_export_menu

    gform_export_menu

    DescriptionUsageParametersExamplesSource Code

    Description
    Add new or modify default menu items which will appear in the Import/Export section menu.
    Usage
    Apply to all forms:
    1add_filter( 'gform_export_menu', 'my_custom_function' );
    Parameters

    $menu_items array
    An array of menu items to be displayed on the Import/Export page menu.

    Examples
    This example demonstrates how you can add a custom menu item to the Import/Export page menu. It also demonstrates (with the use of the gform_export_page_view filter) how to display content for this page when selected.
    1234567891011121314151617181920212223// add custom menu itemadd_filter( 'gform_export_menu', 'my_custom_export_menu_item' );function my_custom_export_menu_item( $menu_items ) {     $menu_items[] = array(        'name' => 'my_custom_export_page',        'label' => __( 'My Custom Export Page' )        );     return $menu_items;} // display content for custom menu item when selectedadd_action( 'gform_export_page_my_custom_export_page', 'my_custom_export_page' );function my_custom_export_page() {     GFExport::page_header();     echo 'My Custom Export Page Settings!';     GFExport::page_footer(); }
    Source Code
    This filter is located in GFExport::get_tabs() in export.php.

    gform_export_fields

    gform_export_fields

    DescriptionUsageParametersExamples1. Add custom field2. Remove fields3. Remove advanced field inputs4. Single columns for multi-input fields5. Include Section FieldsPlacementSource Code

    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
    1add_filter( 'gform_export_fields', 'your_function_name' );

    Parameters

    $form Form Object
    The current form.

    Examples
    1. Add custom field
    This example adds two custom fields to the field selection list.
    1234567add_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.
    12345678910111213141516171819202122232425add_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.
    12345678910111213141516add_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.
    123456789101112131415add_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.

    gform_field_choice_selected_type_form_editor

    gform_field_choice_selected_type_form_editor

    DescriptionUsageParametersExamplePlacementSource Code

    Description
    The 「gform_field_choice_selected_type_form_editor」 JavaScript filter in Gravity Forms allows the 「input type」 for choices (checkbox, radio) to be overridden. This hook is used when custom types have been created and will only be needed with such a special case.
    Usage
    12345gform.addFilter( 'gform_field_choice_selected_type_form_editor', function( type, field ) {    // do stuff      return type;} );

    Parameters

    type string
    The choice selected input type. Defaults to checkbox for checkbox type fields or radio for other field types.

    field Field Object
    The current field.

    Example
    12345678910111213141516add_action( 'gform_admin_pre_render', 'set_choice' );function set_choice( $form ) {    ?>        

    gform_export_page_VIEW

    gform_export_page_VIEW

    DescriptionUsageParametersExamplesSource Code

    Description
    Add custom pages (i.e. 「views」) to the Import/Export section.
    Usage
    Specify the view name after the gform_export_page_ hook name:
    add_action( 'gform_export_page_my_custom_page', 'my_custom_function' );

    Parameters
    There are no parameters for this action.
    Examples
    This example demonstrates how to display the content for your custom page and also how to add a menu item to link to this custom page on the Import/Export section via the gform_export_menu filter.
    // let's add our menu item first with the 'gform_export_menu' filter
    add_filter( 'gform_export_menu', 'my_custom_export_menu_item' );
    function my_custom_export_menu_item( $menu_items ) {

    $menu_items[] = array(
    'name' => 'my_custom_export_page',
    'label' => __( 'My Custom Export Page' )
    );

    return $menu_items;
    }

    // now let's display the the content of our custom page
    add_action( 'gform_export_page_my_custom_export_page', 'my_custom_export_page' );
    function my_custom_export_page() {

    GFExport::page_header();

    echo 'My Custom Export Page Settings!';

    GFExport::page_footer();

    }

    Source Code
    This filter is located in GFExport::export_page() in export.php.

    gform_export_form

    gform_export_form

    DescriptionUsageParametersExamplePlacementSinceSource Code

    Description
    Allows modification of the form meta before export.
    Usage
    The following would apply to all forms:
    add_filter( 'gform_export_form', 'modify_form_for_export', 10, 1 );

    To target a specific form, append the form id to the hook name. (format: gform_export_form_FORMID)
    add_filter( 'gform_export_form_1', 'modify_form_for_export', 10, 1 );

    Parameters

    $form Form Object
    The current form.

    Example
    add_filter( 'gform_export_form', 'modify_form_for_export' );
    function modify_form_for_export( $form ) {
    $form['exported'] = true;
    return $form;
    }

    add_filter( 'gform_export_form', 'modify_form_for_export' );
    function modify_form_for_export( $form ) {
    $form['title'] = 'Export of ' . $form['title'];
    return $form;
    }

    Placement
    This code should be placed in the functions.php file of your active theme.
    Since
    This filter was added in Gravity Forms version 1.8.8.
    Source Code
    This filter is located in GFExport::prepare_forms_for_export() in export.php.

    gform_field_choices

    gform_field_choices

    DescriptionUsageParametersExamplesPlacementSource Code

    Description
    This filter is executed when creating the checkbox or radio button items. It can be used to manipulate the item』s string before it gets added to the checkbox or radio button list.
    Usage
    1add_filter( 'gform_field_choices', 'form_submit_button', 10, 2 );
    Parameters

    $choices string
    The string containing the choices to be filtered i.e.
    1$field Field Object
    The current field.

    Examples
    This example demonstrates how to allow HTML characters on checkbox and radio items.
    12345add_filter( 'gform_field_choices', 'decode_specialchars', 10, 2 );function decode_specialchars( $choices, $field ) {    $choices = htmlspecialchars_decode( $choices );    return $choices;}
    Placement
    This code should be placed in the functions.php file of your active theme.
    Source Code
    This filter is located in the following methods:

    GF_Field_Checkbox::get_checkbox_choices() in includes/fields/class-gf-field-checkbox.php
    GF_Field_Radio::get_radio_choices() in includes/fields/class-gf-field-radio.php

    gform_export_separator

    gform_export_separator

    DescriptionUsageParametersExamplesPlacementSource Code

    Description
    Use this filter to change the column separator character for the entry export file. The default separator is a comma (,).
    Usage
    add_filter( 'gform_export_separator', 'change_separator', 10, 2 );

    You can also target a specific form by adding the form id after the filter name.
    add_filter( 'gform_export_separator_6', 'change_separator', 10, 2 );

    Parameters

    $separator string
    Value of the separator character to be filtered.

    $form_id integer
    ID of the current form.

    Examples
    This example changes the separator to a pipe (|).
    add_filter( 'gform_export_separator', 'change_separator', 10, 2 );
    function change_separator( $separator, $form_id ) {
    return '|';
    }

    Placement
    This code should be placed in the functions.php file of your active theme.
    Source Code
    This action hook is located in GFExport::start_export() in export.php.

    gform_export_forms_forms

    gform_export_forms_forms

    DescriptionUsageParametersExamplesPlacementSinceSource Code

    Description
    The 「gform_export_forms_forms」 filter in Gravity Forms allows the forms displayed on the Export Forms page to be filtered.
    Usage
    1add_filter( 'gform_export_forms_forms', 'your_function_name', 10, 1 );

    Parameters

    $forms array
    The complete list of forms.

    Examples
    123456add_filter( 'gform_export_forms_forms', 'filter_forms', 10, 1 );function filter_forms( $forms ){    //remove half of the forms    $forms = array_slice( $forms, 0, round( count( $forms ) / 2 ) );    return $forms;}
    Placement
    This code should be placed in the functions.php file of your active theme.
    Since
    This filter was added in Gravity Forms version 2.4.6.16.
    Source Code
    This filter is located in GFExport::export_form_page() in export.php.