Using Gravity Forms ‘gform_chainedselects_import_file’ PHP filter

The gform_chainedselects_import_file Gravity Forms PHP filter allows you to provide an import file for the Chained Selects programmatically. This import file will override any previously uploaded file via the field settings.

Usage

A generic example of how to use the filter:

add_filter('gform_chainedselects_import_file', 'your_function_name', 10, 3);

To target a specific form, append the form id to the hook name:

add_filter('gform_chainedselects_import_file_14', 'your_function_name', 10, 3);

To target a specific field id for a form, append the form id and field id to the hook name:

add_filter('gform_chainedselects_import_file_14_2', 'your_function_name', 10, 3);

Parameters

  • $import_file (array): An array of details for the file from which choices will be imported:
    • $url (string): The URL of the file to be imported.
    • $expiration (int): The number of seconds until the import file will be re-imported.
  • $form (Form Object): The form object.
  • $field (Field Object): The field object.

More information

See Gravity Forms Docs: gform_chainedselects_import_file

Examples

Setting a custom import file for chained selects

This example sets a custom import file for the Chained Selects field and sets the expiration to 60 seconds.

add_filter('gform_chainedselects_import_file', 'set_import_file', 10, 3);

function set_import_file($import_file, $form, $field){
  $file_array = array(
      'url' => 'http://localhost/wp.dev/wp-content/plugins/gravityformschainedselects/sample.csv',
      'expiration' => 60
  );
  return $file_array;
}

Setting a custom import file for a specific form

This example sets a custom import file for the Chained Selects field in form 14.

add_filter('gform_chainedselects_import_file_14', 'set_import_file', 10, 3);

function set_import_file($import_file, $form, $field){
  $file_array = array(
      'url' => 'http://localhost/wp.dev/wp-content/plugins/gravityformschainedselects/sample.csv',
      'expiration' => 60
  );
  return $file_array;
}

Setting a custom import file for a specific field in a specific form

This example sets a custom import file for the Chained Selects field with field ID 2 in form 14.

add_filter('gform_chainedselects_import_file_14_2', 'set_import_file', 10, 3);

function set_import_file($import_file, $form, $field){
  $file_array = array(
      'url' => 'http://localhost/wp.dev/wp-content/plugins/gravityformschainedselects/sample.csv',
      'expiration' => 60
  );
  return $file_array;
}