- Posts: 41
- Thank you received: 10
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
What data format for "add_response" parameter (RPC)
- mfaber
- Topic Author
- Offline
- Senior Member
Less
More
11 years 2 weeks ago #93094
by mfaber
What data format for "add_response" parameter (RPC) was created by mfaber
Fellow users and experts,
I'm stuck trying to add a response to the database using a PHP-script and the RPC-function "add_response". I can't make it work, partly because I do not know what the data format (the array containing the responses) should have. I looked up and down and can't find a working example of code/data.
Background: I want to find a way to take surveys offline. So far I export a survey-page (questions all on one page) and change the html form/post command in the html so the answers are mailed "action=mailto:email@email.org". That is: saved in the email-program until the device is online again and then mailed. My plan is to import these mailed answers using an RPC command.
Any advice or example code would be greatly appreciated!
I'm stuck trying to add a response to the database using a PHP-script and the RPC-function "add_response". I can't make it work, partly because I do not know what the data format (the array containing the responses) should have. I looked up and down and can't find a working example of code/data.
Background: I want to find a way to take surveys offline. So far I export a survey-page (questions all on one page) and change the html form/post command in the html so the answers are mailed "action=mailto:email@email.org". That is: saved in the email-program until the device is online again and then mailed. My plan is to import these mailed answers using an RPC command.
Any advice or example code would be greatly appreciated!
The topic has been locked.
- mdekker
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 55
- Thank you received: 12
11 years 2 weeks ago #93101
by mdekker
---
Menno Dekker
Replied by mdekker on topic What data format for "add_response" parameter (RPC)
By looking at the code I think the responsedata should be an array using the fieldnames from the survey_xxxxx table as keys and the answers as values. So the key should be the sidXgidXqid code, that would be a little hard to implement, but I think there is something in the documentation wiki that explains this code and you can always look at the table structure.
I am not really sure if the procedure is tested to work, what kind of response do you get?
I am not really sure if the procedure is tested to work, what kind of response do you get?
---
Menno Dekker
The following user(s) said Thank You: mfaber
The topic has been locked.
- mfaber
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 41
- Thank you received: 10
11 years 2 weeks ago #93110
by mfaber
Replied by mfaber on topic What data format for "add_response" parameter (RPC)
Thanks for your help, mdekker...i will try as soon as I'm back on my test environment.
The output from a one-question survey (which I rerouted from the html form POST-command) looks as follows:
So, first the fieldnames (which already come in the old SGQ-structure. Then the fieldnames and answers and then some logic-related and survey specific data. So I should be able to make this work, at least for smaller surveys.
There seems to be a lot of demand for an offline-solution for limesurvey. There are a lot of these freelancer-websites with such requests and offers. Unfortunately none of them have made it into the official limesurvey code.
The output from a one-question survey (which I rerouted from the html form POST-command) looks as follows:
Code:
fieldnames=171217X171X1634&171217X171X1634=N&java171217X171X1634=N&relevance1634=1&relevanceG0=1&move=movesubmit&thisstep=2&sid=171217&start_time=1361740277&LEMpostKey=1502713047
So, first the fieldnames (which already come in the old SGQ-structure. Then the fieldnames and answers and then some logic-related and survey specific data. So I should be able to make this work, at least for smaller surveys.
There seems to be a lot of demand for an offline-solution for limesurvey. There are a lot of these freelancer-websites with such requests and offers. Unfortunately none of them have made it into the official limesurvey code.
The topic has been locked.
- mfaber
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 41
- Thank you received: 10
11 years 2 weeks ago #93159
by mfaber
Replied by mfaber on topic What data format for "add_response" parameter (RPC)
It works pretty well using the array structure you suggested. And the data from the POST command can easily be converted to an associative array using the parse_str PHP function.
LS's add_response function is just a a bit picky on what to receive as responses. It unfortunatly reacts with a fatal error if something unexpected is contained in the response array. (see bug report: bugs.limesurvey.org/view.php?id=7629 )
Otherwise, i am confident I can make this offline survey solution work.
Will keep you posted.
Thanks again,
M
Code:
$post="542856X167X1616=Y&542856X168X1617=12&542856X168X1618=F&542856X168X1619=6&542856X169X1620=Y&542856X169X1621=&542856X169X1622SQ001=Y&542856X169X1622SQ002=U&542856X169X1622SQ003=N&542856X169X1622SQ004=Y&542856X169X1622SQ005=U&542856X170X1623=Y&542856X170X1624SQ001=Y&542856X170X1624SQ002=U&542856X170X1624SQ003=N&542856X170X1624SQ004="; // convert string to an associative array parse_str($post, $output); // does it look ok? print_r($output); //add response to the LS database $responseadded=$myJSONRPCClient->add_response($sSessionKey, $survey_id, $output); // show the reponse code print_r($responseadded);
LS's add_response function is just a a bit picky on what to receive as responses. It unfortunatly reacts with a fatal error if something unexpected is contained in the response array. (see bug report: bugs.limesurvey.org/view.php?id=7629 )
Otherwise, i am confident I can make this offline survey solution work.
Will keep you posted.
Thanks again,
M
The following user(s) said Thank You: DenisChenu
The topic has been locked.
- mdekker
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 55
- Thank you received: 12
11 years 2 weeks ago #93229
by mdekker
---
Menno Dekker
Replied by mdekker on topic What data format for "add_response" parameter (RPC)
I am sure a lot of people would be interested in your solution. If possible, could you add it to our documentation wiki in the workarounds section?
docs.limesurvey.org/Workarounds&structur...tions+for+LimeSurvey
docs.limesurvey.org/Workarounds&structur...tions+for+LimeSurvey
---
Menno Dekker
The topic has been locked.
- mfaber
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 41
- Thank you received: 10
11 years 2 weeks ago #93270
by mfaber
Replied by mfaber on topic What data format for "add_response" parameter (RPC)
Will do.
I just want to finish writing a script that can handle uploading multiple response files and avoids uploading data that already exist in the LS DB. It was 15 years ago that I last worked as a programmer and I am just learning a bit of PHP through limesurvey. So everything is going a bit slower than I want it to be.... .
I just want to finish writing a script that can handle uploading multiple response files and avoids uploading data that already exist in the LS DB. It was 15 years ago that I last worked as a programmer and I am just learning a bit of PHP through limesurvey. So everything is going a bit slower than I want it to be.... .
The topic has been locked.
- madflow
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 0
10 years 7 months ago #98356
by madflow
Replied by madflow on topic What data format for "add_response" parameter (RPC)
Hi,
I am trying to consume the same exact method in my .Net Application.
But everytime i am getting Result = null.
Paramater that I am passing using Json RPC
{"jsonrpc":"1.0","id":"1","method":"Add_Reponse","params":{"sessionkey":"ABCD","surveyID":"919472","aResponseData":{"submitdate":"07/22/2013","lastpage":"1","startlanguage":"en","919472X6X10":"Y","919472X6X11":"my feedback to you","919472X6X12":"4"}}}
Also i tried the following
{"jsonrpc":"1.0","id":"1","method":"Add_Reponse","params":{"sessionkey":"ABCD","surveyID":"919472","aResponseData":{"919472X6X10":"Y","919472X6X11":"my feedback to you","919472X6X12":"4"}}}
But the Survey response is not getting Added.
The Survey is an Open ended one.
Any pointers as to how to get it working.
I am trying to consume the same exact method in my .Net Application.
But everytime i am getting Result = null.
Paramater that I am passing using Json RPC
{"jsonrpc":"1.0","id":"1","method":"Add_Reponse","params":{"sessionkey":"ABCD","surveyID":"919472","aResponseData":{"submitdate":"07/22/2013","lastpage":"1","startlanguage":"en","919472X6X10":"Y","919472X6X11":"my feedback to you","919472X6X12":"4"}}}
Also i tried the following
{"jsonrpc":"1.0","id":"1","method":"Add_Reponse","params":{"sessionkey":"ABCD","surveyID":"919472","aResponseData":{"919472X6X10":"Y","919472X6X11":"my feedback to you","919472X6X12":"4"}}}
But the Survey response is not getting Added.
The Survey is an Open ended one.
Any pointers as to how to get it working.
The topic has been locked.