This simple survey asks you to select from a range of responses for each question — technically this is called a Likert Scale. The form fields are not hard-coded on the page, but generated dynamically based on records in a database. Two approaches are demonstrated here. Although the forms appear identical, the second is considerably faster, using features provided in TerraForm 2.5 . Click the links to view the working forms.
Note: If this explanation seems convoluted and confusing, skip it and scroll down to the description of the second form (which uses a superior technique) instead.
Normally when we use the TerraForm radio format, we write one cf_terrafield tag to generate a set of radio buttons. However in this example to enable the columnar layout we will manipulate TerraForm by writing one tag for each radio button (in fact we are merely looping over the same cf_terrafield tag, but it makes no difference).
Here's how we have modified TerraForm's normal behavoiur:
cf_terraform flaglabels attribute). However in this case we don't want flags anyway so we use the flagRequiredFields attribute to turn them off.query and displaycolumn attributes, we are providing the valuelist attribute with just one value. This will generate just one button. We loop over this to generate each button. We trick TerraForm into not displaying a caption by passing in a blank space as the displaylist attribute.valuelist or valuecolumn, TerraForm automatically checks the user's value is contained in this list. We need to turn this feature off as each cf_terrafield tag represents only one possible value of the form field.In this case we take advantage of TerraForm 2.5's greater layout flexibility. We don't need to generate each radio button as an individual cf_terraform tag, so we can avoid the workarounds above, and our form will perform much better (in this case the speed gain is around 500 - 1000%). Instead, each row is represented by one cf_terraform tag, which is as it should be. (Actually we are using a cfloop to iterate over the same physical tag, but we are giving the tag a new name each time so TerraForm thinks it's a set of different tags.)
When TerraForm reads our cf_terrafield tag's radio format, it attempts to create a grid of radio buttons arranged in rows and columns. By default, TerraForm splits our buttons into rows of length n where n is specified using the cols attribute. With TerraForm 2.5, you can specify cols="0" to tell TerraForm not to split the buttons into multiple rows. We could say cols="5" but we might want to add more choices in future so we'll use cols="0" instead.
Terraform uses table, tr, and td tags to provide this grid layout. However in TerraForm 2.5 you can override these tags using the gridstart, gridend, rowstart, rowend, cellstart, and cellend tags. We want to tell TerraForm not to use any grid or row tags at all as we already have our table layout. All we want TerraForm to do is wrap <td> and </td> around each radio button. So we set gridstart, gridend, rowstart, and rowend all to "" — an empty string. As we haven't changed the cellstart and cellend attributes, TerraForm will continue to wrap each radio button in the <td> and </td> tags which is all that we require.