Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Sending JSON when insert query !

Sending JSON when insert query ! 4 years 10 months ago #73546

  • rodeo_fly
  • rodeo_fly's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
Hi,

first of all bravo for limesurvey...it is simply the best opensource survey application.

I'd like to send, via ajax, the survey once completed as a json object to a rest service (to add it as an object into a rails application) when clicking on submit button.

It would be very kind if you could tell me where is the best place to insert that code and may be a hint on how you would do this.

I'm not a php programmer but I'll probably have to use json_encode, won't have ?

tks in advance
Last Edit: 4 years 10 months ago by rodeo_fly.
The administrator has disabled public write access.

Sending JSON when insert query ! 4 years 10 months ago #73560

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
What data do you want to send by json?

If you are not a programmer, it will be hardly impossible to set this up. One alternative solution might be to automatically redirect the user to a to be coded PHP script which gets passed some parameters and then does what you need and forwards data to the Rails system.

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

Sending JSON when insert query ! 4 years 10 months ago #73582

  • rodeo_fly
  • rodeo_fly's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
Hi, thanks for answer !
Actually I am a programmer and I want to do what you've just described.
There's this csv export function in limesurvey. Basically I want the same result but json formatted. If I get this json then sending it to rails is a piece of cake.

since your answer I've found this :
www.cparker15.com/code/utilities/csv-to-json/

so Json equivalent of this :
"id","Complété","Dernière page vue","Langue de départ","Code","date du prelevement","nom ou numero","sexe","Age","AgHBs","AgHBc","AcHBs","AcBHs valeur"
"1","2012-01-29 09:17:07","2","fr","","2012-01-29","12456","Masculin","25","positif","positif","positif","999"

would be this

[
{
"id": "1",
"Complété": "2012-01-29 09:17:07",
"Dernière page vue": "2",
"Langue de départ": "fr",
"Code": "",
"date du prelevement": "2012-01-29",
"nom ou numero": "12456",
"sexe": "Masculin",
"Age": "25",
"AgHBs": "positif",
"AgHBc": "positif",
"AcHBs": "positif",
"AcBHs valeur": "999"
}
]
then I send via ajax to my rails app and it stores it automatically as an openstruct attribute of any model !

Would be great !
Last Edit: 4 years 10 months ago by rodeo_fly.
The administrator has disabled public write access.

Sending JSON when insert query ! 4 years 10 months ago #73594

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
You can place such an Ajax call at the source of the end message using teh source code mode of the editor.

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'"
The administrator has disabled public write access.
The following user(s) said Thank You: rodeo_fly

Sending JSON when insert query ! 4 years 10 months ago #73649

  • rodeo_fly
  • rodeo_fly's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
But the main probleme remian how to get a json or cvs file in one click at the end of the survey ?
May be I can call the script directly with some pre-configured parameters (like in the screenshot) to get a cvs file with not too much pain ?


screenshot
Last Edit: 4 years 10 months ago by rodeo_fly.
The administrator has disabled public write access.

Sending JSON when insert query ! 4 years 10 months ago #73653

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9600
  • Thank you received: 1376
  • Karma: 390
Hello,

You want json with code only or with all sentence ?

The easiest way can be code only : only one table.

You can put an ajax request at the endpage.pstpl, call a personnal php file with a sql request and a json_encode instruction.

For all sentence : look at the export php function (export_data_functions.php) to get some inspiration :).

There a lot of way to do some json with php :)

Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
The administrator has disabled public write access.
The following user(s) said Thank You: rodeo_fly

Sending JSON when insert query ! 4 years 10 months ago #73656

  • rodeo_fly
  • rodeo_fly's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
Thank you Shnoulle, but I'm sure you understand that json is not really a problem ; the actual problem is the sql query to get the individual survey with headcode instead of 57338X1X3 and qcode as well.

So I'm going to digg export_data_functions.php to get some inspiration :)
The administrator has disabled public write access.

Sending JSON when insert query ! 4 years 10 months ago #73661

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
Also have a look at the createfieldmap() function, it might make your life easier.

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

get Json or CSV when submit Survey 4 years 10 months ago #73721

  • rodeo_fly
  • rodeo_fly's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
Well after have been diving into this complex code to get The query you can get with 8 clics through limesurvey to get a csv file...I'll choose the manual way for now. I saw that this is not the first time that people ask for that function and as an evidence it is not straight forward (multiple dozens of LOC) !

May be ver 2.0 will be clearer. Anyway thanks for your help guys and may the force be with u ^_^

ps: I've jsut notice that my topic subject was incredibly badly written : should have been "get Json or CSV when submit Survey !". froggies are useless anyway ;)
The administrator has disabled public write access.

get Json or CSV when submit Survey 4 years 10 months ago #73747

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
Once you have found a running solution, please post it here for others. Thanks!

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

get Json or CSV when submit Survey 4 years 10 months ago #73787

  • rodeo_fly
  • rodeo_fly's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
Well I am not even near to it
And this is not very conforting :
www.limesurvey.org/fr/forum/can-i-do-thi...limesurvey-responses
:D

all rite it's not that funny but it means that this is wanted for years !
Serioulsly where is the guy who wrote this huge exportsresult.php ?
Don't you think it would take so many time for this guru to provide a simple script to get csv ?

Let's be constructive maybe some others will have the will and with the will we can everythings...yes we can !

foreach($_POST as $key=>$value)
{
echo $key."=".$value."&";
}
gives us
export_from=1&export_to=3&filterinc=show&exportstyle=headcodes&answers=short&convertyto=1&convertnto=2&type=csv&sid=63226&answerid=3&colselect=Array&checksessionbypost=vutv73gwdq

so wee need all those parameters to get our csv but we can't run the script from outside the admin.php or else we get a warning on csrf token violation

If I just take the script outside and comment the line...ahem ^_^

When I look again to that function my arms are falling down on the floor...How come this two csv lines are so complex to produce ???
Last Edit: 4 years 10 months ago by rodeo_fly.
The administrator has disabled public write access.

get Json or CSV when submit Survey 4 years 10 months ago #73810

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
For Limesurvey 2.0 we are porting all code to the MVC framework "Yii". I'm not sure if thise file was already properly restructured but you can check out the "limesurvey_yii" branch to have a look and test.
For the upcoming Google Summer of Code (if we will be accepted again by Google this year), there might be a task to create an API for such cases, see docs.limesurvey.org/Project+Ideas+for+GSoC+2012

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'"
The administrator has disabled public write access.
Time to create page: 0.494 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form