Welcome to the LimeSurvey Community Forum

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

Storing and returning HTML formatted text.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 weeks 3 days ago #264872 by linuxhooligan
Storing and returning HTML formatted text. was created by linuxhooligan
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.6.55+240220
Own server or LimeSurvey hosting:  shared hosting
Survey theme/template: fruity
==================
I am doing a few deep dives into what kinds of variables I can store and play with.  There are a lot of good options:

* Question: Equation
* Question: Array Text
* Question: Array Number

I am building a report and one of the things I "think" I want to do is store formatted HTML and then have the results appear in a page with a report.  The reason for this would be to make the final formula simpler to read, debug and update.

Currently, I can store everything that I need in the ArrayText question type but when I return the result of that field as {VARarraytext}, this outputs the string including the html as plain text that encapsulates the return in html tags so the results ends up looking something like: "<b>My sentence.</b>"

QUESTION: Is there a way to either store fully formatted text and return the html, or perhaps somehow just make sure that the return of a string is not encapsulated in html tages on a page?

I think that I may actually be abusing Limesurvey with this approach and I would be happy to hear any comments and suggestions including "don't do that, this is a bad idea".

Thanks for any feedback.
 

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 3 days ago #264875 by DenisChenu
Replied by DenisChenu on topic Storing and returning HTML formatted text.
Where did you return the HTML ?
How did you return the HTML ?

Why you need to store HTML ?

A solution is to construct your HTML directly in the content of a question and use {MyQuestion.question} in end page, for example.

Do you know gitlab.com/SondagesPro/ExportAndStats/pdfReport ?

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.

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 weeks 2 days ago - 3 weeks 2 days ago #264894 by linuxhooligan
Replied by linuxhooligan on topic Storing and returning HTML formatted text.
Here is a small example of what I am trying to do:

<p>{join(if(VAR_adaptability>27,VAL01adaptability,''),if(VAR_anxiety>27,VAL02anxiety_SQ001,''),if(VAR_artappreciation>27,VAL03artappreciation,''))}</p>

I am:

1) I am using an Array Numbers question to store the numeric results of a quiz.

2) I am using an Array Text question to store the text values of responses that I want to provide based on the results of the test.

3) In the provided code sample, I do a test for each test item:

a) If test item (VARitem) is greater than 27 return (VALitem) otherwise return nothing.

b) VARitem refers to the array numbers question. VALitem refers to the array text question.

4) What I was expecting to be able to do is embed <b> <i> <div> tags as necessary in order to style up text stores in VALitem.

Currently I have to do it manually inside '<b>this</b><i>that</i>' and limesurvey seems to actually have problems parsing anything other than plain text inside of ' '. For example:

{join(if(VAR_adaptability>27,'<br>this</b><i>that</i>',''),if(VAR_anxiety>27,VAL02anxiety_SQ001,''),if(VAR_artappreciation>27,VAL03artappreciation,''))}

The reason that I am trying to store html is that the top statement is much easier to debug than the bottom expression script statement.  The bottom expression script also has problems parsing and rendering depending on the tags used, I have not figured out yet what the specific cause of the issue might be.

5) Here is what actually happens:

a) Lets say I want to store some html formatted text into an array text question as follows:  {VARarraytext_SQ001_2='<span style="border-radius:25px;background:#73AD21;padding:20px;width:200px;height:150px;">asdfasdf asdfasadf </span>'}

b) Let's say that I want to present that html formatted text on a page with: {VARarraytext_SQ001_2}

c) I get the following result with the text encapsulated in html (which makes sense, I am not complaining): <p><span style="border-radius:25px;background:#73AD21;padding:20px;width:200px;height:150px;">asdfasdf asdfasadf </span></p>

QUESTION: Is it possible to store html tags in array text questions or do i have to manually style up the answers like in the code sample here in point #4?
Last edit: 3 weeks 2 days ago by linuxhooligan.

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 weeks 2 days ago - 3 weeks 1 day ago #264896 by linuxhooligan
Replied by linuxhooligan on topic Storing and returning HTML formatted text.
For reference point, if anyone has not yet tried to do inline styling, here is what a basic two factor (testing for two personality traits) last page report might look like:
Code:
 
<div style="border-radius: 25px;border: 2px solid #73AD21;padding: 20px;">
 
{join(
 
 
 
if(VAR_adaptability>27,join(
 
'<span style="font-weight',
':',
'bold;">',
'ANXIETY - Your score is: ',
VAR_anxiety,
'</span>',
 
'<br />',
 
'<span style="font-style',
':',
'italic;">',
'A brief description.',
'</span>',
 
'<br />',
 
'<span style="font-style',
':',
'font-size:16px;">',
'Another supplementary description.',
'</span>',
 
'<br /><br />'
 
),''),
 
 
if(VAR_anxiety>27,join(
 
'<span style="font-weight',
':',
'bold;">',
'ANXIETY - Your score is: ',
VAR_anxiety,
'</span>',
 
'<br />',
 
'<span style="font-style',
':',
'italic;">',
'A brief description.',
'</span>',
 
'<br />',
 
'<span style="font-style',
':',
'font-size:16px;">',
'Another supplementary description.',
'</span>',
 
'<br /><br />'
 
),''),
 
)}
 
</div>
 

Please note that it is spaced vertically like that for "maintainability" as developing a somewhat complicate survey requires that the actuall expression script be documented somewhere and made easy to update + copy paste back into the web interface.

However, if you pay attention to the substantial amount of apppend required for the join to to create the proper <span style=".."> tags without triggering parsing errors in Limesurvey makes something like this EXTREMELY unwieldy.

This is a live example of WHY I wanted to just shove a whole bunch of html tagged content into an Array Text question and then just be able to do VAR_item to have it display properly. That would be much easier to maintain.

For any noobs out there looking for examples on how to use join in a slightly more complicated way, this example here is pretty good.  It is based on the example from this page:  manual.limesurvey.org/ExpressionScript_examples
Last edit: 3 weeks 1 day ago by linuxhooligan.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 2 days ago #264897 by Joffm
Replied by Joffm on topic Storing and returning HTML formatted text.
You have to use
"html_entity_decode(x)"
[url] manual.limesurvey.org/ExpressionScript_-...mplemented_functions [/url]

Several threads about this
[url] forums.limesurvey.org/forum/can-i-do-thi...xt-nested-conditions [/url]





Nevertheless: Did you consider pdfReport?
And you should use classes.

Joffm

P.S.
If you enter code, please use the "code" button of the editor.
It's easier to read.

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 2 days ago #264901 by DenisChenu
Replied by DenisChenu on topic Storing and returning HTML formatted text.
1. I really never try to put HTML in answers part
2. I always deactivate HTML editor for complex part
3. I use multiple Question type - Text display when it's complex
4. If filterxsshtml is activated : i can not start a tag but not close on same function
5. If filterxsshtml is activated : i can not use html_entity_decode

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.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 1 day ago #264907 by Joffm
Replied by Joffm on topic Storing and returning HTML formatted text.
Fully agreed, @Denis.

One more word.
Why do you expect to get something else than plain text like '<span style="color:red"><b>Tralala</b></span>'
LimeSurvey doesn't know that you want to use inline css.
It's a text answer like everything else.
In a test it could be the answer to questions like
"Please enter the inline css to display the word "Tralala" in bold and red."
"Which HTML tag is used for an inline container?"
In these cases you obviously do not want the answer to be rendered.

Therefore you have to tell that it is displayed as HTMl code.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 weeks 1 day ago #264911 by linuxhooligan
Replied by linuxhooligan on topic Storing and returning HTML formatted text.
Amazing feedback, including the critiques. Just to answer this question:

"Why do you expect to get something else than plain text like '<span style="color:red"><b>Tralala</b></span>'"

You are correct, I expect Lime to consider entries in questions as strings. As per recommendation html_entity_decode(x) is precisely what I was looking for.

Thank you for that.

Denis said the following: 1. I really never try to put HTML in answers part

What does this mean? Does Limesurvey have an ability to use variables? All of the examples that I have seen so far use questions to store data and later perform operations on this data in various ways. Denis, are you saying there is another way to store data?

I have a survey with about 200 questions and the final page needs to take the data and:

* Sort 30 possible options into 4 categories.
* Only show the questions in the category they score in.
* Display the 4 categories (of up to 30 possible options each) in a nice way which requires, divs, css classes and as little parsing and appending using join as possible because that is impossible to debug and maintain.

The logical way to do this is to collect the totals and store them in one questions. Store the answers (perhaps with html formatting) in another question, store various triggers in a third question and then on the report page compose the final report using THIS_that_value.

Is there a better way to do this?

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 6 hours ago - 3 weeks 6 hours ago #264920 by DenisChenu
Replied by DenisChenu on topic Storing and returning HTML formatted text.
> What does this mean? Does Limesurvey have an ability to use variables?

Answer part : variable to be exported, and variable without HTML.

You can use MyQuestion.question for variable too : HTML allowed, no data saved, more clean.

I do HTML report since years now. It's really more easy to work with .question than with .NAOK.

But you can do what you want … it's just advice …

> The logical way to do this is to collect the totals and store them in one questions. Store the answers (perhaps with html formatting) in another question, store various triggers in a third question and then on the report page compose the final report using THIS_that_value.

When i need this : i use some text display question, and after a final report

{if(Q01.NAOK,Report1.question)}{if(Q02.NAOK,Report2.question)}

etc …

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.
Last edit: 3 weeks 6 hours ago by DenisChenu.

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 weeks 5 hours ago #264922 by linuxhooligan
Replied by linuxhooligan on topic Storing and returning HTML formatted text.
Very much appreciate everyones suggestions. I will do HTML report and my nest step is to look into pdfReport as well.

I hope this helps other noobs as well when they search.

Thank you for your time.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose