GF_Field_Dropbox

Introduction

The GF_Field_Dropbox class extends the GF_Field class, also known as the Field Object, it’s responsible for determining how the Dropbox Upload field is rendered when the form is displayed and how it’s value is handled during and after submission.

Properties

These are the properties used by the Dropbox Upload field, which can be found in the Field Object, available to many of the hooks throughout Gravity Forms and some add-ons.

  • type string

    The field type, which in this case is dropbox.

  • id integer

    The field ID.

  • label string

    The field label that will be displayed on the form and on the admin pages.

  • adminLabel string

    The label to be used on admin pages instead of the label, useful for fields with long labels.

  • isRequired boolean

    Determines if the field requires the user to select a file for upload. Marking the field as required will prevent the form from being submitted if a file is not selected. Default is false.

  • errorMessage string

    The custom error message to be displayed if the field fails validation.

  • labelPlacement string

    The field label visibility. Empty when using the form defaults or a value of ‘hidden_label’.

  • descriptionPlacement string

    The field description position. Empty when using the form defaults, a value of ‘below’ to position the description below the input container, or a value of ‘above’ to position the description above the input container.

  • multiselect boolean

    Allow multiple files to be selected? Default is false.

  • allowedExtensions string

    A comma separated string of allowed file extensions. e.g. jpg,gif,png

  • formId integer

    The ID of the form this field is located on.

  • pageNumber integer

    The form page this field is located on. Default is 1.

  • conditionalLogic array

    An associative array containing the conditional logic rules. See the Conditional Logic Object for more details.

  • description string

    The field description.

  • cssClass string

    The custom CSS class or classes to be added to the li tag that contains the field.

Dynamic Population

Unfortunately the Dropbox Upload field does not currently support dynamic population.

Calculations Support

Unfortunately the Dropbox Upload field can’t currently be used with calculations; we do have this on the feature request list.

Conditional Logic Support

Unfortunately you can’t configure conditional logic rules on other fields based on the Dropbox Upload field; we do have this on the feature request list.

$entry Value

The Dropbox Upload field stores file urls in the Entry Object as a string in the following format:

["https://www.dropbox.com/link-one","https://www.dropbox.com/link-two"]

When accessing the field value in the Entry Object you will most likely want to decode the above so you can do something with each url. Here’s an example:

$value = rgar( $entry, '3' );
$files = json_decode( $value, true );
foreach ( $files as $file ) {
    // do something with the $file
}

Merge Tags

The field merge tag available via the merge tag drop down in notifications and confirmations will return the field value. Each URL will be returned on it’s own line.

{[Field Label]:[field_id]} e.g. {Dropbox Upload:3}

The Dropbox Upload field does not have any modifiers for the field merge tag.

The {all_fields} merge tag will return an unordered HTML list. For each list item the filename will be wrapped in a HTML link. If the notification format is changed to text then the value returned will be identical to that returned when using the field merge tag.

Useful Methods

GF_Field_Dropbox inherits it’s available methods from GF_Field and overrides a few of them where necessary to provide its required appearance and functionality. Here are a few methods which can be useful when writing custom code.

get_value_export()

The get_value_export() method formats the entry value before it is used in entry exports and by framework add-ons that integrate with third-party services, however, you can use it in your custom code when interacting with the Form Object, Field Object and Entry Object.

Usage Examples

// if you have access to the $field object
$value = $field->get_value_export( $entry );

// if you don't have access to the $field object
$value = GF_Field_Dropbox::get_value_export( $entry, $input_id );
  • $entry Entry Object

    The entry from which the field value should be retrieved. Required.

  • $input_id string

    The ID of the field for which the value should be retrieved. Required when not using $field. Defaults to the $field->id property when not supplied.

  • Returns string

    The file url. If the entry value contains multiple urls then they will be separated by a comma with a space either side e.g.

    https://www.dropbox.com/link-one , https://www.dropbox.com/link-two

Source Code

The GF_Field_Dropbox class is located in includes/class-gf-field-dropbox.php in the Gravity Forms Dropbox Add-On folder of your sites plugins directory.

The GF_Field class is located in includes/fields/class-gf-field.php in the Gravity Forms folder of your sites plugins directory.