Combining text and data

Last updated on November 22, 2024

Combining text and data in forms.

On this page:

Overview

Sometimes you want to combine data and text into a sentence or phrase.

  • You could use Template parameters in Explanatory Text, or
  • You could enter a formula in the Calculated Value of a control

If the combination you are looking for is complex or conditional, you may find it easier to use the concat() function in a Calculated Value.

For additional information. see:

Using the concat() function

The concat() function combines a series of arguments separated by commas into a single string of text. An argument can be a text set off by single quotes or a value from another field. You can use this function to create short statements, or whole paragraphs.

The general format for the function is:

concat(argument, argument, argument, ... )

Example

You have a form where the submitter can claim zero to 3 hours for standing by at the site of an event, in half-hour increments. The hourly rate they can claim is determined elsewhere in the form. You want to be able to produce a statement on the PDF output to describe the number of hours and the rate they are claiming.

To do this, you'll want:

  • A control called $hourlyRate that applies the hourly rate the claimant is entitled to
  • A control called $standbyClaim that accepts zero to 3 hours in half-hour increments, such as through radio buttons
  • A control called $standbyStatement that combines text and the values of $hourlyRate and $standbyClaim

Consider making the control $standbyStatement visible when using a test layer to make it easier to see and confirm that the statement is compiling correctly.

The formula for this could be:

if (string($standbyClaim) > '0') then
   concat(
      'Standby charge   (',
      string($standbyClaim),
      ' hours x $',
      string($hourlyRate),
      '/hr)'
      )
    
else 'Standby charge   (none)'

This conditional formula can produce 2 statements:

  • If there is no claim made, the statement would read: Standby charge   (none)
  • If there is a claim made, the statement would read (example): Standby charge    (1.5 hours x $84.25/hr)

This allows us to confirm in the PDF that no claim was made if there wasn't one, rather than just leaving the statement blank.