How can we receive complex tabular data in a Gravity Form?
For example, I recently had need of receiving the above information for a service profile. In this post, we’ll walk through how you can setup the native GF list field to meet this need.
Apart from Gravity Forms, there are no other special tools needed to setup this solution.
Add List Field & Define Columns
Our first step is to add a list field in our form. Enable multiple columns and add headings for each column. Take note of the heading you give the first column as you will need this to auto-populate the row headings.
Enable Dynamic Population
Under the Advanced tab, you will check to Allow field to be populated dynamically. Be sure to set a parameter name for dynamic population. You’ll need this later, too.
Dynamically Populate Row Headers
This is where the good stuff begins to happen. In order to populate the row headers, we will utilize the
gform_field_value_$parameter_name filter. Using code from this gist (shown below), ensure you’ve properly set the filter name according to the dynamic population parameter name you set for the field. Then set the list array according to the column you want to populate.
- The key in each row’s array element must exactly match the header you set for the column.
- The value will define the row header you want for each row.
Set Row Headers As readonly & Prevent Row Removal
tabindex attribute (so that they are removed from the tab flow of the form).