Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Email template, content should depend on answers given in survey

  • timdec19
  • timdec19's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 6 months ago #189330 by timdec19
I have a survey with a signup form with 2 questions:
- textfield for email
- dropdown selection list with options like 'student', 'teacher', etc

After completing the survey the user should receive an automatic email (this works already) but the content should depend on the signup type, as teachers have to pay less than students.

I have been trying something like this in the email template field:
Code:
Thanks for signing up!
{if(signup_type=="A1")} { Please pay €5 }
{if(signup_type=="A2")} { Please pay €10 }

But this does not work. What is the correct way of using such logic expressions in the email?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 6 months ago - 4 years 6 months ago #189333 by holch
Your code is completely wrong, so I assume this is the problem here. I am assuming that "signup_type" and A1, A2, etc. are correct, then you should try this code:
Code:
{if(signup_type=="A1", "Please pay €5", "")}
{if(signup_type=="A2", "Please pay €10", "")}

It is always like this {if(condition that triggers something, what happens when condition is met, what happens when condition is not met)}

Or, assuming that there is only signup type A1 and A2 you could write this shorter:
Code:
{if(signup_type=="A1", "Please pay €5", "Please pay €10")}


I would always try this code within the survey first (e.g. in a text display question or an equation question) and see if it works there (easier to make sure the code works, because you do not need to send an email each time). Once the code works, then you can try it in the email template.

Actually, I probably would use a hidden equation question for this and in the email Template I would probably just pipe the content of this Equation question into the email. This way it is even saved in the database.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 4 years 6 months ago by holch.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 6 months ago #189334 by Joffm
And in addition to holch's explanation:

You find all this here:
manual.limesurvey.org/Expression_Manager...mplemented_functions
and here
manual.limesurvey.org/Expression_Manager_how-tos

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
3 years 11 months ago #198766 by BusyBonsai
Hi guys. I am used to the if-functions syntax and using it in question texts etc. on a regular basis. However, right now I am trying to implement it in the email invitation template and it seems to just swallow up the curly brackets. See my attempts below.

I am using LS version 2.73.0+171219 for this.
Code:
<html>
<head>
  <title></title>
</head>
<body>
<p>{if(TOKEN:ATTRIBUTE_1 == "1", "Lieber Kollege Prof. ", "")} {if(TOKEN:ATTRIBUTE_1 == "2", "Liebe Kollegin Prof. ", "")}{if(TOKEN:ATTRIBUTE_1 == "1", "Lieber Kollege Prof. ", if(TOKEN:ATTRIBUTE_1 == "2", "Liebe Kollegin Prof. ", "Sehr geehrte*r Prof. "))}{LASTNAME},<br />

And the screenshot shows it's validating properly clicking on the "Validate expressions" button.

Guess I need some captain obvious here.
The topic has been locked.
More
3 years 11 months ago #198782 by BusyBonsai
Edit: email I am receiving looks like this
The topic has been locked.
More
3 years 11 months ago #199457 by BusyBonsai
Hi there.

Turns out that - within EMail-templates - instead of "TOKEN:ATTRIBUTE_1" you need to write "ATTRIBUTE_1" only. It works fine now for me.

Cheers
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #199492 by holch
Yes, this is one of these little "inconsistencies" that can drive you nuts. I don't understand why this is not consistent, but it is the way it is.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #199502 by DenisChenu
If i don't make error in 3.X : you can use TOKEN:ATTRIBUTE_1 or ATTRIBUTE_1

If you can not in 4.X : it's a (major) issue

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose