Check out the LimeSurvey source code on GitHub!

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

5 years 2 weeks ago #73930 by yannischris
I am trying to make a very simple example, according to your instructions and with the help of the example you pinpointed. So:

I created a php file (helloWolrd.php) and placed it in upload/templates/:

echo "HelloWorld!";

Then I placed some javascript code in the source of the question, which just calls the php file and requests data:

<script type="text/javascript" charset="utf-8">
$.getJSON('templates/helloWorld.php', function(data) {

So I expected to see an alert window showing "Hello World!", but nothing happens... Am I missing something?!

Please Log in to join the conversation.

5 years 2 weeks ago #74008 by Something

yannischris wrote: 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?"

yannischris wrote: 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?

I found a good example / tutorial that I followed and worked flawlessly. I am not sure if I am allowed to post external links here, but you can find it in google search using the keywords "how to retrieve data from mysql using javascript". It's the 2nd result.

It describes how to use javascript with ajax in order to a) make a customizable mysql query from within a webpage, and b) to display the resulting data on the same page. The connection to the database is done by means of a php file.

In my local installation of Limesurvey (using xampp) I placed the php file in the htdocs/limesurvey directory (where also other limesurvey php files are located) and it worked fine.

Hope you find this info helpful!

Please Log in to join the conversation.

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