Formidable Forms

The Most Advanced WordPress Forms Plugin and Form Builder

  • Features
  • Pricing
  • Blog
  • Support
  • Login
  • Get Formidable Forms

frm_csv_columns

Last Updated: April 30, 2018

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → CSV and XML Management → frm_csv_columns
Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

This hook can be used to manipulate the columns that appear in .csv files that are exported.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

Usage

add_filter( 'frm_csv_columns', 'remove_id_column', 10, 2 );
function remove_id_column( $headings, $form_id )

Parameters

  • $headings (array)
  • $form_id (integer)

Examples

Remove ID Column on Export

You can use the example below to remove the ID column and all of it's entry information from the .csv file of a particular form upon export.

add_filter( 'frm_csv_columns', 'remove_id_column', 10, 2 );
function remove_id_column( $headings, $form_id ) {
  if ( $form_id == 5 ) { //change 5 to your Form ID
    unset( $headings['id'] ); //change id to the header of the column to be removed
  }
  return $headings;
}

Change the name of a column

If you are importing your CSV into another service, you may need specific names for each column. You can either set your field labels to the names you need, or you can change the names for the export.

add_filter( 'frm_csv_columns', 'change_column_name', 10, 2 );
function change_column_name( $headings, $form_id ) {
  $new_labels = array( 25 => 'New label', 26 => 'Another label' ); //change 25 and 26 to your Field IDs, and the labels to the ones you would like to use
  foreach ( $new_labels as $field_id => $label ) {
    if ( isset( $headings[ $field_id ] ) ) { 
      $headings[ $field_id ] = $label;
    }
  }
  return $headings;
}

Export specific columns

Use the code below to limit your exported CSV to a few specific columns. Replace 19 with your form ID. Replace 363, 425, 579, and 'id' with the columns you want to export.

add_filter( 'frm_csv_columns', 'export_specific_cols', 10, 2 );
function export_specific_cols( $headings, $form_id ) {
	if ( $form_id == 19 ) {
		$export_columns = array( 363, 425, 579, 'id' );
		foreach ( $headings as $col_key => $data ) {
			if ( ! in_array( $col_key, $export_columns ) ) {
				unset( $headings[ $col_key ] );
			}
		}
	}
	return $headings;
}

Remove All Meta Columns

This example removes all of the meta columns that show things like when the entry was created, by whom, etc.

add_filter( 'frm_csv_columns', 'remove_id_column', 10, 2 );
function remove_id_column( $headings, $form_id ) {
if ( $form_id == 5 ) { //change 5 to your Form ID
  unset( $headings['created_at'] );
  unset( $headings['updated_at'] );
  unset( $headings['user_id'] );
  unset( $headings['updated_by'] );
  unset( $headings['is_draft'] );
  unset( $headings['ip'] );
  unset( $headings['id'] ); //change id to the header of the column to be removed
  unset( $headings['item_key'] );
}
return $headings;
}

Remove Extra Address Columns on Export

By default, when exporting a form with an Address Field, there will be a column with the complete address, as well as extra columns with the separate parts of the address (line1, line2, city, state, etc.) You can use this custom code to remove the extra columns. Please note, if you have a country dropdown in your Address Field, you will want to uncomment the last column below.

add_filter( 'frm_csv_columns', 'remove_extra_address_columns', 10, 2 );
function remove_extra_address_columns( $headings, $form_id ) {
  if ( $form_id == 568 ) { //change 568 to your Form ID
    $address_field_id = '3855'; //change 3855 to your Adress Field ID
    unset( $headings[$address_field_id . '_line1'] );
    unset( $headings[$address_field_id . '_line2'] );
    unset( $headings[$address_field_id . '_city'] );
    unset( $headings[$address_field_id . '_state'] );
    unset( $headings[$address_field_id . '_zip'] );
    //unset( $headings[$address_field_id . '_country'] ); //uncomment this line if you are using an International Address Layout
  }
  return $headings;
}

Remove Label Column

Use this code to remove the label column, including all of its entries, when using separate values for checkbox, radio, or dropdown fields.

add_filter( 'frm_csv_columns', 'remove_label_column', 10, 2 );
function remove_label_column( $headings, $form_id ) {
  if ( $form_id == 326 ) { //change 326 to your Form ID
    unset( $headings['4002_label'] ); //change 4002 to the field ID using separate values
  }
  return $headings;
}
  • Usage
  • Parameters
  • Examples
    • Remove ID Column on Export
    • Change the name of a column
    • Export specific columns
    • Remove All Meta Columns
    • Remove Extra Address Columns on Export
    • Remove Label Column
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms
Install Formidable Lite

Using WordPress and want to get Formidable Forms for free?

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact

Top Features

  • Front End Editor
  • Repeating Fields
  • Views from Entries
  • Calculator Forms
  • Conditional Logic
  • Visual Form Styler
  • Form Templates
  • User Submitted Posts
  • File Upload Forms
  • Spam Protection
  • Multi Page Forms
  • Surveys & Polls
  • Form Graphs & Charts
  • Save and Continue
  • Mobile Forms
  • Stripe Forms
  • PayPal Forms
  • WooCommerce Forms
  • MailChimp Forms
  • User Registration
  • Signature Forms
  • Bootstrap Forms
  • Quiz Maker
  • Zapier Forms
  • Salesforce Forms
  • HubSpot Forms
  • API Webhooks
  • Multilingual Forms
  • Directories

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • Blog

Copyright © 2021 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started See User Reviews