- Posts: 11
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Placeholder for attachment
1 week 17 hours ago - 1 week 17 hours ago #241487
by darpao
Placeholder for attachment was created by darpao
Your LimeSurvey version: 5.6.8+230227
Own server or LimeSurvey hosting: own
Survey theme/template: fruits
==================
I need to print a final summary of the fields of the survey.
When I try to show the name and the title of an attachment I can only see with {G01Q09.shown} this:
[{ "title":"title inserted","comment":"","size":"589.63671875","name":"19102022.pdf","filename":"fu_6nzjjxkrdjw6uh9","ext":"pdf" }]
How can I print only "title inserted" and 19102022.pdf? Is there a way?
Thank you
Own server or LimeSurvey hosting: own
Survey theme/template: fruits
==================
I need to print a final summary of the fields of the survey.
When I try to show the name and the title of an attachment I can only see with {G01Q09.shown} this:
[{ "title":"title inserted","comment":"","size":"589.63671875","name":"19102022.pdf","filename":"fu_6nzjjxkrdjw6uh9","ext":"pdf" }]
How can I print only "title inserted" and 19102022.pdf? Is there a way?
Thank you
Last edit: 1 week 17 hours ago by darpao.
Please Log in to join the conversation.
1 week 17 hours ago - 1 week 15 hours ago #241491
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Placeholder for attachment
Use some string functions like "strstr", "strpos", "substr" to extract the desired parts in one or more equations.
[url] manual.limesurvey.org/ExpressionScript_-...mplemented_functions [/url]
Like this:
eqTitle: {substr(Q1,14,strpos(Q1,"comment")-14-3)}
eqFname: {substr(Q1,strpos(Q1,"name")+7,strpos(Q1,"filename")-3-strpos(Q1,"name")-7)}
or you use "join" and only one equation
eqAttach: {join("Title: ",substr(Q1,14,strpos(Q1,"comment")-14-3)," Filename: ",substr(Q1,strpos(Q1,"name")+7,strpos(Q1,"filename")-3-strpos(Q1,"name")-7))}
to get
But this is up to you.
Joffm
[url] manual.limesurvey.org/ExpressionScript_-...mplemented_functions [/url]
Like this:
eqTitle: {substr(Q1,14,strpos(Q1,"comment")-14-3)}
eqFname: {substr(Q1,strpos(Q1,"name")+7,strpos(Q1,"filename")-3-strpos(Q1,"name")-7)}
or you use "join" and only one equation
eqAttach: {join("Title: ",substr(Q1,14,strpos(Q1,"comment")-14-3)," Filename: ",substr(Q1,strpos(Q1,"name")+7,strpos(Q1,"filename")-3-strpos(Q1,"name")-7))}
to get
But this is up to you.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 week 15 hours ago by Joffm.
The following user(s) said Thank You: DenisChenu, darpao
Please Log in to join the conversation.
1 week 11 hours ago #241504
by darpao
Replied by darpao on topic Placeholder for attachment
Thank you Joffm, it works for 1 attachment, but maybe I can have problems because the user can upload up to 10 files.
In this case I should use strpos offset but the formula could be complicated.
I have [{ "title":"title inserted","comment":"","size":"589.63671875","name":"19102022.pdf","filename":"fu_6nzjjxkrdjw6uh9","ext":"pdf" },{ "title":"title2 inserted","comment":"","size":"589.63671875","name":"20102022.pdf","filename":"fu_6nzjjxkrdjw6uh9","ext":"pdf" },{ "title":"title3 inserted","comment":"","size":"589.63671875","name":"21102022.pdf","filename":"fu_6nzjjxkrdjw6uh9","ext":"pdf" }]
But now I understood that I can use php inside the placeholders and perhaps I can use explode function or something else creating an array and then exctract information from a key-value array.
I don't know how to deal with it because I don't use php since 2010, but I can try!
In this case I should use strpos offset but the formula could be complicated.
I have [{ "title":"title inserted","comment":"","size":"589.63671875","name":"19102022.pdf","filename":"fu_6nzjjxkrdjw6uh9","ext":"pdf" },{ "title":"title2 inserted","comment":"","size":"589.63671875","name":"20102022.pdf","filename":"fu_6nzjjxkrdjw6uh9","ext":"pdf" },{ "title":"title3 inserted","comment":"","size":"589.63671875","name":"21102022.pdf","filename":"fu_6nzjjxkrdjw6uh9","ext":"pdf" }]
But now I understood that I can use php inside the placeholders and perhaps I can use explode function or something else creating an array and then exctract information from a key-value array.
I don't know how to deal with it because I don't use php since 2010, but I can try!
Please Log in to join the conversation.
1 week 11 hours ago #241505
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Placeholder for attachment
You are not using PHP directly, you are using implemented ExpressionScript functions. Look at the link Joffm provided.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
1 week 10 hours ago #241506
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Placeholder for attachment
Sorry,
but you get what you ask for.
Of course you can use javascript.
On the other hand you can select title and filename of the first attachment, then remove this with
eqDel1: {substr(Q1,strpos(Q1,"}"))}
select title and filename of the second, remove this
and so on.
Joffm
but you get what you ask for.
Of course you can use javascript.
On the other hand you can select title and filename of the first attachment, then remove this with
eqDel1: {substr(Q1,strpos(Q1,"}"))}
select title and filename of the second, remove this
and so on.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- DenisChenu
-
- Offline
- LimeSurvey Community Team
-
Less
More
- Posts: 12886
- Thank you received: 2371
1 week 9 hours ago #241507
by DenisChenu
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.
Replied by DenisChenu on topic Placeholder for attachment
If you're good on PHP : i think it can be done in Plugin now
See : manual.limesurvey.org/ExpressionManagerStart
And the sample, with a question code , some json_decode etc … it can be easy for another page.
For same page : a script to add the link to download the file
See : manual.limesurvey.org/ExpressionManagerStart
And the sample, with a question code , some json_decode etc … it can be easy for another page.
For same page : a script to add the link to download the file
Code:
/* LINK ON UPLOADED FILES */ function updateLink(element) { let jsonValue = $(element).attr('value'); let fieldname = $(element).attr('name').replace("java",""); let afieldname = fieldname.split("X"); let dataUpload = jQuery.parseJSON( jsonValue ); let url = "/index.php?r=uploader/index?sid=" + afieldname[0] +"&fieldname=" + fieldname + "&qid=" + afieldname[2] + "&filegetcontents="; if(typeof dataUpload == 'object') { table = $(element).closest(".upload-files.question-container").find(".ls-answers table.uploadedfiles"); $.each(dataUpload, function( index, uploaded ) { let link = url + uploaded.filename; let cell = $(table).find("tbody tr").eq(index).find('td.edit'); let filename = $(cell).text(); $(cell).off('click'); $(cell).html("<a href='" + link + "' target='_blank' download='" + filename + "'>" + filename + "</a>"); }); } } $(document).on('ready',function(){ $(".upload-item :hidden:first").each(function(){ var element = $(this); setTimeout(function() { updateLink($(element)); }, 500); }); }) $(document).on("updated",".upload-item :hidden:first",function(event){ var element = $(this); setTimeout(function() { updateLink($(element)); }, 500); });
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.