November 16th, 2015: Updated to work with current version of Gravity Forms.
August 8th, 2015: Updated to work with Gravity Forms 2.0+
<?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. | |
* | |
* @version 1.2 | |
* @author David Smith <david@gravitywiz.com> | |
* @license GPL-2.0+ | |
* @link http://gravitywiz.com/how-do-i-export-multi-input-fields-in-a-single-column-with-gravity-forms/ | |
* @copyright 2015 Gravity Wiz | |
* | |
* Plugin Name: Gravity Forms - Export Multi-input Fields in Single Column | |
* Plugin URI: http://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: http://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; | |
} ); |
@bamadesigner asked:
Is there a way to export lead checkbox values from @gravityforms into one column as a CSV instead of a column for each checkbox? #WordPress
— Rachel Carden (@bamadesigner) August 2, 2015
I cooked up a quick snippet (using the gform_export_fields filter) to allow you to not only export checkboxes but all multi-input fields in a single column.
What are multi-input fields? They’re fields like the Checkbox field, Name Field, Address field, Multi Select field, etc. Out of the box, Gravity Forms allows you export the individual inputs of these fields in separate column but not all of the inputs in a single column.
Use this snippet to automatically add a “top level” option that will export all inputs for this field in a single column.
How do I install this?
- Click the “Download Plugin” button at the top of this page.
- Upload the downloaded plugin zip file via your WordPress admin (full instructions).
Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 32+ essential add-ons for Gravity Forms with support you can count on.
Hi,
Does this snippet work with List fields? It does seem to work well with address, and checkbox fields.
Thanks Shawn
Hey David,
Do you know if this still works with the latest version of GF? I’ve tried adding the code to our child themes functions.php file, and also tried the plugin. Neither option works. Your old screenshots no longer work so I can’t see where to check for a new field etc. Could you please add screenshots to the article?
Thank you
Hi Shaun,
I just did a test and I can confirm the snippet still works. After adding the snippet to the function.php file, you should see a top-level option that similar to the screenshot here, In that screenshot, the multi-input field is a checkbox field and the checkbox field has been made available by the snippet for selection to export all the choices selected for that field in a single column.
I hope this helps.
Best,