Introduction
The GF_Field_List class extends the GF_Field class, also known as the Field Object. This class is responsible for determining how the List field is rendered when the form is displayed and how its value is handled during and after submission.
Settings and Properties
Settings control what options are available to the admin user when configuring the field in the form editor. Gravity Forms includes many built-in settings such as Field Label, Field Description, Choices, Conditional Logic, etc. In addition to built-in settings, custom settings can also be developed. For more information on how to develop custom settings and how to associate settings to a field, visit the GF_Field page.
Properties contain the values specified by the settings and generally are part of the Field Object.
The properties may be retrieved by accessing the Field Object as follows:
//get the field $field = GFFormsModel::get_field( $form, 1 ); //get the admin label $admin_label = $field->adminLabel;
Settings
The following settings are available for the field:
- add_icon_url_setting
Determines whether the “Add Icon URL” section displays. This allows a URL to be entered to point to a different image to be used for the add row icon. -
admin_label_setting
Controls whether the “Admin Field Label” setting appears. -
columns_setting
Determines whether the “Enable multiple columns” section displays. This allows the List field to have more than the default one column, with each column having a distinct name. -
conditional_logic_field_setting
Controls whether the “Enable Conditional Logic” setting appears. -
css_class_setting
Controls whether the “Custom CSS Class” setting displays. This allows a custom css to be used for the field. -
delete_icon_url_setting
Determines whether the “Delete Icon URL” section displays. This allows a URL to be entered to point to a different image to be used for the delete row icon. -
description_setting
Controls whether the “Description” setting appears. This allows a description for the field to be displayed. -
error_message_setting
Controls whether the “Custom Validation Message” setting which allows a custom message to be used appears. -
label_setting
Controls whether the “Field Label” setting which allows the label to be changed appears. -
maxrows_setting
Determines whether the “Maximum Rows” section displays. This allows a limit to be set for how many rows may be added as the form is filled out. -
prepopulate_field_setting
Controls whether the “Allow field to be populated dynamically” setting appears. -
rules_setting
Controls whether the “Rules” settings section displays. The “Required” option shows when this is active. -
visibility_setting
Controls whether the “Visibility” setting displays. The controls whether the option of visibility being for “Everyone” or “Admin Only” can be set.
Properties
These are the properties used by the List field, which can be found in the Field Object, available to many of the hooks throughout Gravity Forms and some add-ons.
- addIconUrl string
The URL of the image to be used for the add row button.
-
adminLabel string
The label to be used on admin pages instead of the label, useful for fields with long labels.
-
allowsPrepopulate boolean
Determines in the field value can be dynamically populated. Default is false.
-
choices array
An array containing the column labels. Only used when enableColumns is true.
$choices = array( array( 'text' => 'Column 1', 'value' => 'Column 1', ), array( 'text' => 'Column 2', 'value' => 'Column 2', ), array( 'text' => 'Column 3', 'value' => 'Column 3', ), );
Each column is an associative array containing the following properties:
-
conditionalLogic array
An associative array containing the conditional logic rules. See the Conditional Logic Object for more details.
-
cssClass string
The custom CSS class or classes to be added to the li tag that contains the field.
-
deleteIconUrl string
The URL of the image to be used for the delete row button.
-
description string
The field description.
-
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.
-
enableColumns boolean
Determines if the field should use multiple columns. Default is false.
-
errorMessage string
The custom error message to be displayed if the field fails validation.
-
formId integer
The ID of the form this field is located on.
-
id integer
The field ID.
-
inputName string
The parameter name used when dynamically populating the field. Only used when allowsPrepopulate is true.
-
isRequired boolean
Marking the field as required will prevent the form from being submitted if the user does not enter a value. Default is false.
-
label string
The field label that will be displayed on the form and on the admin pages.
-
labelPlacement string
The field label visibility. Empty when using the form defaults or a value of ‘hidden_label’.
-
maxRows integer
The maximum number of rows the user can add to the field.
-
pageNumber integer
The form page this field is located on. Default is 1.
-
type string
The field type, which in this case is list.
Dynamic Population
When dynamically populating the List field via query string or the field_values parameter of the gravityform shortcode or the gravity_form function the required format is a string e.g. col1_row1|col2_row1,col1_row2|col2_row2
An array can be used to dynamically populate the field when using the gform_field_value_parameter_name filter.
If you are using the gravity_form function and have an array it would need to be converted to a string. You can do this by first serializing the array using the php serialize function and then passing that to get_value_entry_detail() which will return the dynamic population compatible string.
Calculations Support
Unfortunately the List 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 List field; we do have this on the feature request list.
$entry Value
The List field value is stored in the Entry Object as a serialized string. So if you submit this:
You will find the following in the entry:
a:3:{i:0;a:3:{s:8:"Column 1";s:3:"one";s:8:"Column 2";s:3:"two";s:8:"Column 3";s:5:"three";}i:1;a:3:{s:8:"Column 1";s:1:"i";s:8:"Column 2";s:2:"ii";s:8:"Column 3";s:3:"iii";}i:2;a:3:{s:8:"Column 1";s:1:"1";s:8:"Column 2";s:1:"2";s:8:"Column 3";s:1:"3";}}
When accessing the field value in the Entry Object you will want to unserialize it like so:
$list_values = unserialize( rgar( $entry, '3' ) );
You will then have an array which contains an associative array for each row. In each array the column label will be used as the key to the value.
$list_values = array( array( 'Column 1' => 'one', 'Column 2' => 'two', 'Column 3' => 'three', ), array( 'Column 1' => 'i', 'Column 2' => 'ii', 'Column 3' => 'iii', ), array( 'Column 1' => '1', 'Column 2' => '2', 'Column 3' => '3', ), );
Merge Tags
The field merge tag available via the merge tag drop down in notifications and confirmations will return the field entry value formatted as a table when the field has columns or as an unordered list.
{[Field Label]:[field_id]}
e.g. {List:3}
You can use the :url modifier to return the field value as a string which could be used in a query string e.g. {List:3:url}
would return one|1|i,two|2|ii,three|3|iii
.
You can also use the gform_merge_tag_filter to implement your own custom modifiers to output an individual columns values.
The {all_fields}
merge tag will return an unordered HTML list or a HTML table when multiple columns are enabled.
Useful Methods
GF_Field_List 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_entry_detail()
The get_value_entry_detail() method formats the entry value before it is used in notifications, confirmations, and the entry detail page.
Usage Examples
// if you have access to the $field object $value = $field->get_value_entry_detail( $value ); // if you don't have access to the $field object $value = GF_Field_List::get_value_entry_detail( $value, '', false, 'url' );
- $value string
The serialized string to be formatted.
-
$currency string
Not relevant to this field type. Default is an empty string.
-
$use_text boolean
Not relevant to this field type. Default is false.
-
$format string
How should the returned value be formatted. Default is html. Alternatives are text or url.
-
$media string
Where is the value being used. Default is screen. Alternative is email.
-
Returns string
An unordered HTML list or a HTML table when multiple columns are enabled and the $format is set to html. A comma and pipe separated string when the $format is url. A comma separated string when the $format is text.
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_List::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. To access values for a specific column you can include the column number (zero based) with the field id e.g 3.1 would return the values from the second column.
-
Returns string
The values for a single column returned as comma separated string. When columns are enabled and a column number is not specified the entry value will be converted to a json string.
Hooks
The following hooks are located in GF_Field_List:
Source Code
The GF_Field_List class is located in includes/fields/class-gf-field-list.php in the Gravity Forms folder of your sites plugins directory.