- Posts: 12880
- Thank you received: 3964
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Provide custom code to each participant
- LouisGac
- Visitor
5 years 8 months ago #171860
by LouisGac
I suggest you to have a look in the theme views, it should be the easiest way to do it or to write a plungin, as Denis suggested.
This view is the one rendering the final page after completion:
github.com/LimeSurvey/LimeSurvey/blob/ma.../content/submit.twig
Replied by LouisGac on topic Provide custom code to each participant
istewart6 wrote: Great, thanks. I'll look into php scripts to handle this.
To answer your question, the codes are predefined which is why I wanted to upload a single file containing all the codes. You can generate them using an API but it's a bit complicated.
I suggest you to have a look in the theme views, it should be the easiest way to do it or to write a plungin, as Denis suggested.
This view is the one rendering the final page after completion:
github.com/LimeSurvey/LimeSurvey/blob/ma.../content/submit.twig
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
5 years 8 months ago #171861
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Provide custom code to each participant
Here an example for an open survey with less codes than participants.
Surely you can reformat of your list by some formulas or macros in EXCEL to be able to just copy and paste it to LS.
Best regards
Joffm
Surely you can reformat of your list by some formulas or macros in EXCEL to be able to just copy and paste it to LS.
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12880
- Thank you received: 3964
5 years 8 months ago #171870
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Provide custom code to each participant
Hi,
here a different approach.
You don't like to have the code list inside the survey.
So I took the opportunity to try an ajax call.
In a question (Q1) of type "short free text" I inserted the following script:
The php-script "getCode.php":
Here I used a plain array to store the codes.
Of course you can store the codes in a database and retrieve them by SQL; but the example should be short and easy.
Therefore thee are no error checks at all.
It was my first try with ajax calls in LS. So any improvement is appreciated.
Especially how to hide the question if it is in "question by question" mode.
Here I used "group by group" mode and had a second visible question in this group.
Best regards
Joffm
here a different approach.
You don't like to have the code list inside the survey.
So I took the opportunity to try an ajax call.
In a question (Q1) of type "short free text" I inserted the following script:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ $.post('https://www.myServer.com/directory/getCode.php', function(data) { $('#question{QID} input[type="text"]').val(data) }); $('#question{QID}').hide(); }); </script>
The php-script "getCode.php":
Here I used a plain array to store the codes.
Code:
<?php $codes = array ( "aaaaaa", "bbbbbb", "cccccc", ... "yyyyyy", "zzzzzz" ); $numberOfCodes=count($codes)-1; $random=rand(0,$numberOfCodes); echo ($codes[$random]); ?>
Of course you can store the codes in a database and retrieve them by SQL; but the example should be short and easy.
Therefore thee are no error checks at all.
It was my first try with ajax calls in LS. So any improvement is appreciated.
Especially how to hide the question if it is in "question by question" mode.
Here I used "group by group" mode and had a second visible question in this group.
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: LouisGac
The topic has been locked.
- stewart
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 0
5 years 8 months ago #172000
by stewart
Replied by stewart on topic Provide custom code to each participant
Thanks for the examples, Joffm. I think this is the best way to approach the problem, but I need to host the codes on a separate server to ensure privacy. Can you suggest a simple way to set that up?
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12880
- Thank you received: 3964
5 years 8 months ago #172001
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Provide custom code to each participant
Hi,
well, my Limesurvey installation is on " www.example1.com/survey " and the phpfile is on " www.example2.com/mydirectory/getCode.php ".
To be more sophisticated:
You can place the codes encrypted in a database.
Change the php to connect to the database, get the code, decrypt it....
So it's up to you to adapt it to your needs.
I just gave a simple example.
Best regards
Joffm
Joffm
well, my Limesurvey installation is on " www.example1.com/survey " and the phpfile is on " www.example2.com/mydirectory/getCode.php ".
To be more sophisticated:
You can place the codes encrypted in a database.
Change the php to connect to the database, get the code, decrypt it....
So it's up to you to adapt it to your needs.
I just gave a simple example.
Best regards
Joffm
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.