Using Gravity Forms ‘gform_export_line’ PHP action

The gform_export_line Gravity Forms PHP filter allows you to filter the current line being exported.

Usage

add_filter('gform_export_line', 'your_custom_function', 10, 6);

Parameters

  • $line (string): The current line being exported.
  • $form (array): The current form object.
  • $fields (array): An array of field IDs to be exported.
  • $field_rows (array): An array of List fields.
  • $entry (array): The current entry.
  • $separator (string): The separator.

More information

See Gravity Forms Docs: gform_export_line

Examples

Append custom text to each line

function append_custom_text($line, $form, $fields, $field_rows, $entry, $separator) {
  // Append custom text to each line
  $line .= $separator . 'Custom Text';
  return $line;
}
add_filter('gform_export_line', 'append_custom_text', 10, 6);

Change separator for specific form

function change_separator_for_form($line, $form, $fields, $field_rows, $entry, $separator) {
  if ($form['id'] == 1) {
    // Change separator for specific form
    $separator = '|';
  }
  return $line;
}
add_filter('gform_export_line', 'change_separator_for_form', 10, 6);

Remove specific field from export

function remove_field_from_export($line, $form, $fields, $field_rows, $entry, $separator) {
  $field_to_remove = 5; // Field ID to remove
  $export_values = explode($separator, $line);
  $new_export_values = array();

  foreach ($fields as $index => $field) {
    if ($field['id'] != $field_to_remove) {
      $new_export_values[] = $export_values[$index];
    }
  }

  return implode($separator, $new_export_values);
}
add_filter('gform_export_line', 'remove_field_from_export', 10, 6);

Replace empty values with custom text

function replace_empty_values($line, $form, $fields, $field_rows, $entry, $separator) {
  $export_values = explode($separator, $line);
  $new_export_values = array();

  foreach ($export_values as $value) {
    $new_export_values[] = empty($value) ? 'N/A' : $value;
  }

  return implode($separator, $new_export_values);
}
add_filter('gform_export_line', 'replace_empty_values', 10, 6);

Modify specific field value

function modify_specific_field_value($line, $form, $fields, $field_rows, $entry, $separator) {
  $field_to_modify = 3; // Field ID to modify
  $export_values = explode($separator, $line);

  foreach ($fields as $index => $field) {
    if ($field['id'] == $field_to_modify) {
      $export_values[$index] = 'Modified Value'; // Change value
    }
  }

  return implode($separator, $export_values);
}
add_filter('gform_export_line', 'modify_specific_field_value', 10, 6);