06
Apr

Sections

  • Font size: Larger Smaller
  • Hits: 2483
  • Print

A section is a part of the form that we want the user to add several times with the same structure. Each section contains its own layout and set of fields included.

To configure a new section go to ‘sections’ tab of your calculator, create a new section and fill in the following data:

  • Name: This is the identifier of the section.
  • View add button: Choose if you will allow user to add new blocks.
  • Number of default sections: Number of blocks that will be shown by default when form is created.
  • Limit section: Maximum number of blocks user can add to the section.
  • Fields to include: Select which of the fields configured at ‘fields and code’ section will be included for this section.

We'll create an example with 3 simple fields. We want the user to be able to add as many rows as needed to enter new data. We’ll show a row created by default, and will allow up to 10 rows of data. The name of the section will be ‘section1’.

Sections layout.

Once the section is created, you must configure the layout of the section, and locate the section itself inside the main form of the calculator. Go to 'form layout', and you will see new options that will allow you to configure your main layout and the sections layout.

Switch among the main frontend tab and your sections to configure your preferred layout for each of them. Switch among the editors clicking on their names. At the left side you will see information about which fields belong to the main form or are assigned to the sections.

When building sections layout you can also use the layout helpers to create 1/2/3 columns layout with a single click. For this example we’ll include our 3 fields in a single row.

At the main layout, you must place the section as well. To include the section, change to main layout editor and include the section at the required place. Use the ##xxx## sintax same way it’s done with the other fields.


This form will show at the front-end as follows:

You will note our selected fields are inside a special block where users can add or delete new blocks.

You can download the example calculator 'sections' from your customer area to check how these steps are configured in a working calculator.

Data handling
When dealing with sections, the variables recovered from the form don’t have a single value anymore. You will have to use them as an array, like you do with multioption values. For ex: if you configure a field 'mynumber' and you use it inside a section, at the code you will have
$mynumber[0]
containing the value of the first row
$mynumber[1]
containing the value of the second row, and so on.

In PHP, arrays have a huge set of functions available for handling them in many ways, you have
count($mynumber)
that will return the number of elements you have at the array
you can loop over all the elements of the array using for or foreach structure...etc. Ex:
//this code will sum all values from all rows
$result=0;
for($i=0;$icount($mynumer);$i++){
$result=$result+$mynumber[$i];
}

We share a ulr to the official PHP docs full of examples and use cases where you can learn about all options available about arrays.
Array Functions

Last modified on
Trackback URL for this blog entry.

Our clients' feedback