Welcome, Guest
Username: Password: Remember me

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

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 7 months ago #73448

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 7 months ago #73467

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?
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 7 months ago #73488

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 7 months ago #73492

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?
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 7 months ago #73516

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 6 months ago #73899

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?"
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 6 months ago #73900

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 6 months ago #73907

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?
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 6 months ago #73914

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 6 months ago #73918

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?
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.122 seconds
Donation Image