Export Multi-input Fields in a Single Column

Export multi-input Gravity Forms fields as a single column.

Read the Walkthrough

Code

Filename: gw-export-multi-input-fields-single-colum.php

<?php
/**
 * Gravity Wiz // Gravity Forms // Export Multi-input Fields in a Single Column
 *
 * By default, Gravity Forms only allows you to export each input of a multi-input field (e.g. Checkbox field,
 * Name Field, etc) as a separate column. This snippet allows you to export all inputs (of a specific field) in a
 * single column.
 *
 * Plugin Name: Gravity Forms - Export Multi-input Fields in Single Column
 * Plugin URI: https://gravitywiz.com/how-do-i-export-multi-input-fields-in-a-single-column-with-gravity-forms/
 * Description: Export multi-input Gravity Forms fields as a single column.
 * Author: David Smith
 * Version: 1.2
 * Author URI: https://gravitywiz.com
 */
add_filter( 'gform_export_fields', function( $form ) {

	// only modify the form object when the form is loaded for field selection; not when actually exporting
	if ( rgpost( 'export_lead' ) || rgpost( 'action' ) == 'gf_process_export' ) {
		return $form;
	}

	$fields = array();

	foreach ( $form['fields'] as $field ) {
		if ( is_a( $field, 'GF_Field' ) && is_array( $field->inputs ) ) {
			$orig_field    = clone $field;
			$field->inputs = null;
			$fields[]      = $field;
			$fields[]      = $orig_field;
		} else {
			$fields[] = $field;
		}
	}

	$form['fields'] = $fields;

	return $form;
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.