Using the Repeater element, you can display a form section multiple times in the same interactive form. For example, a form section containing a “Name”, “Address” and “City” fields can be used by more than one interactive form. This saves an editor time because he or she does not have to add these fields over and over in different forms. Suppose you want to add these values to an e-mail. Adding the values of the repeaters, even when they are empty, can lead to an unprofessional presentation. Furthermore, you want the e-mails that you send out to be personal. This article explains how you can personalize text and/or e-mails so that only the relevant values from repeater elements are shown.
Requirements
In order to use a Repeater element, you need to create at least one form section. After that, you can add a Repeater element to an interactive form. This article describes an e-mail message, therefore you also need to add an e-mail handler to a form. It can be in multiple languages or in just one language.
This article describes a situation in which the name of a person who is attending a meeting who will be sent a list of fellow attendees.
Desired Situation
We want to format an e-mail message in which only the fields on the form that have been filled in are retrieved. This includes situations such as a form that contains 3 fields but only 2 have been filled in.
Solution
In order to retrieve the values from the form, we use Javascript that has been added to the E-mail handler. The following code shows how you can retrieve the value from the “Name” field and use it in an e-mail message. For example:
Dear $step1.naam.value$,
You have confirmed that you will attend the meeting.
Thank you for contacting us.
The first step has an identifier “step1” and a text element in which the name of the person is entered “name”.
Similarly, the Repeater element retrieves the values for the field (note: the following is pseudo code):
[stap identifier].[repeater identifier].repeat[index repeater].[veld identifier].value
In this example, we retrieved the names as follows:
Dear $step1.naam.value$,
You have confirmed that you will attend the meeting. The following people will also be in attendance:
$step1.additional_people.repeat0.name.value$ $step1.additional_people.repeat1.name.value$ $step1.additional_people.repeat2.name.value$ $step1.additional_people.repeat3.name.value$
Thank you for contacting us.
The problem is that this method can introduce unwanted white space in the e-mail message if an empty value is retrieved from a field that was not filled in. You can solve this problem by retrieving the values from the Repeater within a piece of JavaScript code. Couple a variable with a value provided that it has been filled in. The following code example shows how to do that:
Dear $step1.name.value$,
You have confirmed that you will attend the meeting. The following people wil also be in attendance:
$
var mail='';
if(step1.additional_people.repeat0.name.value!==""){
mail = mail + "\n" + step1.additional_people.repeat0.name.value;
}
if(step1.additional_people.repeat1.name.value!==""){
mail = mail + "\n" + step1.additional_people.repeat1.name.value;
}
if(step1.additionale_people.repeat2.name.value!==""){
mail = mail + "\n" + step1.additional_people.repeat2.name.value;
}
if(step1.additional_people.repeat3.name.value!==""){
mail = mail + "\n" + step1.additional_people.repeat3.name.value;
}
mail;
$
Thank you for contacting us.
In this code snippet, the “mail” variable is created. Next, for each step of the Repeater, a check is done to see whether the value of the “Name” field is empty. If it is not empty (“==”), then the variable acquires the value of the e-mail address followed by a rule that retrieves the name that was filled in. This is done for each Repeater element.
In the last step, the e-mail variable is returned in which all the required values are stored.
The image below shows an example in which some fields are empty and what the end result is:
Remarks
Enkele opmerkingen omtrent het bovenstaande:
Some remarks regarding the above example:
- Make sure that there are always as many repeat[index] values as there are choices. If there are too few, some values will not be retrieved and if there are too many, the code will not be able to run completely.
- You must add all the repeat checks by hand. Create an “if” statement and then use copy/paste for the others and then modify the pasted statements. If done properly, you only have to do this once.
- If there are multiple values that need to be checked, use code similar to the following
if(step1.additionele_personen.repeat0.naam.value!=="" && step1.additionele_personen.repeat0.email.value!=="")
- If you want to know how to deal with radio buttons in a form, see the code in the article “Using simple formatting in an e-mail”.
Comments
0 comments
Article is closed for comments.