Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Sending JSON when insert query !

Sending JSON when insert query ! 2 years 8 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: 2 years 8 months ago by rodeo_fly.
The administrator has disabled public write access.

Re: Sending JSON when insert query ! 2 years 8 months ago #73560

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

Re: Sending JSON when insert query ! 2 years 8 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: 2 years 8 months ago by rodeo_fly.
The administrator has disabled public write access.

Re: Sending JSON when insert query ! 2 years 8 months ago #73594

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.
The following user(s) said Thank You: rodeo_fly

Re: Sending JSON when insert query ! 2 years 8 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: 2 years 8 months ago by rodeo_fly.
The administrator has disabled public write access.

Re: Sending JSON when insert query ! 2 years 8 months ago #73653

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6429
  • Thank you received: 840
  • Karma: 249
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
The administrator has disabled public write access.
The following user(s) said Thank You: rodeo_fly

Re: Sending JSON when insert query ! 2 years 8 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.

Re: Sending JSON when insert query ! 2 years 8 months ago #73661

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

get Json or CSV when submit Survey 2 years 8 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.

Re: get Json or CSV when submit Survey 2 years 8 months ago #73747

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.134 seconds
Donation Image