Welcome to the LimeSurvey Community Forum

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

Insert line break in string

  • lwolters
  • lwolters's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 3 months ago #114879 by lwolters
Insert line break in string was created by lwolters
I have Q1, Q2 and Q3 all ask for a certain symptom to be present, yes or no. Then I have a hidden question Q4, which constructs a string like this:
{if(Q1 == 'Y', 'symptom 1<br />',''}{if(Q2 == 'Y', 'symptom 2<br />',''}{if(Q3 == 'Y', 'symptom 3<br />','')}
The next couple of questions recall the string constructed in Q4, i.e. Q5: 'The symptoms are:{Q4.NAOK}'

Now, if the questions are displayed on the same page, in Q5 etc. every <br /> gives a line break as wanted. But I need the questions to be displayed one by one and then the <br/> does not insert a line break but is literaly displayed as part of the string.

I also tried to use the \n in combination with nl2br(), but this does'nt work at all.

Can anyone please help me out?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago #114881 by tpartner
Replied by tpartner on topic Insert line break in string
Try using HTML entities and the entity_decode() function - manual.limesurvey.org/Expression_Manager#Access_to_Functions

Code:
{if(Q1 == 'Y', html_entity_decode('symptom 1&amp;lt;br /&amp;gt;'), '')}{if(Q2 == 'Y', html_entity_decode('symptom 2&amp;lt;br /&amp;gt;'), '')}{if(Q3 == 'Y', html_entity_decode('symptom 3&amp;lt;br /&amp;gt;'), '')}

.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: lwolters
The topic has been locked.
  • lwolters
  • lwolters's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 3 months ago #114937 by lwolters
Replied by lwolters on topic Insert line break in string
Thanks for your reply. I tried this solution but again the HTML-tag is literally shown. The output is:
The symptoms are symptom 2<br />symptom 3<br />
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago - 9 years 3 months ago #114940 by tpartner
Replied by tpartner on topic Insert line break in string
Working survey attached.

Try disabling the WYSIWYG editor when modifying that question. Perhaps the editor is converting the HTML entities back to tags.

File Attachment:

File Name: limesurvey...1-27.lss
File Size:14 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 3 months ago by tpartner.
The topic has been locked.
  • lwolters
  • lwolters's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 3 months ago #114950 by lwolters
Replied by lwolters on topic Insert line break in string
Thanks for your help again. My problem is that when (in your sample questionnaire) you make boilerPlate1 an (hidden) equation and then recall boilerPlate1 in later questions, the linebreaks have been disappeared. I'd like to recall 'boilerPlate1' because there is a number of questions where I need a list of symptoms and in the real questionnaire this list is quiet long.
I attached my testsurvey.

File Attachment:

File Name: limesurvey...1114.lss
File Size:19 KB
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago - 9 years 3 months ago #114984 by tpartner
Replied by tpartner on topic Insert line break in string
Okay, how about this?

1) Place something like this in your equation question (let's call it equation1):
Code:
{if(Q1 == 'Y', htmlentities('symptom 1<br />'), '')}{if(Q2 == 'Y', htmlentities('symptom 2<br />'), '')}{if(Q3 == 'Y', htmlentities('symptom 3<br />'), '')}

2) And where you want to display it:
Code:
{html_entity_decode(equation1)}

New sample survey:

File Attachment:

File Name: limesurvey...5171.lss
File Size:15 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 3 months ago by tpartner.
The following user(s) said Thank You: lwolters
The topic has been locked.
  • lwolters
  • lwolters's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 3 months ago #114985 by lwolters
Replied by lwolters on topic Insert line break in string
It works :) ! Thank you very much for your help.
best regards,
Liselot
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose