Check out the LimeSurvey source code on GitHub!

Connect LimeSurvey with database (or any other form of text storage)

More
5 years 3 weeks ago #73448 by Mazi

yannischris wrote: And if I want to pre-fill an answer, but this time from the answers of another (answered) survey, rather than from the token table? Can I as well use javascript to load these answers from the lime_survey_12345 table?

That won't be possible technically. When using Javascript, you can't query the DB. The additional token attribute data is available as placeholder like {TOKEN:FIRSTNAME} which you can out into (hidden) survey elements and then it gets replaced on page call and can be read out using Javascript.
If you want to read out data from a different lime_survey_12345 table, you would need to use an Ajax call.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 3 weeks ago #73467 by yannischris
Holch referred to the place where the custom attribute fields are stored as "token table" so I figured that this is a table that is also stored in the DB, together with the lime_survey_12345 table.

But it's good that I can do it with Ajax calls. I suppose that it is done in a similar way as with javascript, i.e. make an ajax call to the DB on page load, fetch data and pre-fill the relevant fields in the survey.

I searched the forum and the manual but Ι can't seem to find any sample code for making ajax calls to db. Has anybody done something similar? Where could I find some example code for that?

Please Log in to join the conversation.

More
5 years 3 weeks ago #73488 by Mazi

yannischris wrote: I searched the forum and the manual but Ι can't seem to find any sample code for making ajax calls to db. Has anybody done something similar? Where could I find some example code for that?

The described approach is correct. An Ajax example can be found here: docs.limesurvey.org/Workarounds%3A+Manip...wers_for_text_inputs

There should also be some forum topics about it.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 3 weeks ago #73492 by yannischris
I checked the ajax example but from what I understand, it only covers the case that the answer is text. But what about if the asnswer is e.g. a radio button or some other form other than just text?

Please Log in to join the conversation.

More
5 years 3 weeks ago #73516 by Mazi
In this case you have to refer to the answer code of the answer which you want to be pre-checked by default. If you take a look at the HTML source of a question, you should see how such radio buttons are named and can trigger them using JS.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 2 weeks ago #73899 by yannischris

Mazi wrote:

yannischris wrote: I searched the forum and the manual but Ι can't seem to find any sample code for making ajax calls to db. Has anybody done something similar? Where could I find some example code for that?

The described approach is correct. An Ajax example can be found here: docs.limesurvey.org/Workarounds%3A+Manip...wers_for_text_inputs


I checked out this example but I don't think that the script makes a connection with a database. IT reads files from a csv file, which is a different case. So the question remains:
Is there a a way to query a database in order to pre-fill the answer of a question in a limesurvey questionnaire?"

Please Log in to join the conversation.

More
5 years 2 weeks ago #73900 by Mazi
You are right, these are different topics. But the core issue I wanted to poibnt to is how to call any PHP script from within Limesurvey. Once that is done, you just have to add the according code to query data from another DB and hand it back to Limesurvey which can be done with some adjustments.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 2 weeks ago #73907 by yannischris
ok I see! In the manual it says that I should place the php file in the template directory. But where can I find this template directory?

Please Log in to join the conversation.

More
5 years 2 weeks ago #73914 by Mazi
When accessing the system using FTP you find the user templates at /upload/templates/<templatename>


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 2 weeks ago #73918 by yannischris
So if I place a php script there, the javascript automatically locates the script (given that I have provided the right name)?
And if this php script fetches data from a db, can it pass those data to the javascript, which in turns can use them to e.g. prefill answers to the questionnaire?

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form