-
Notifications
You must be signed in to change notification settings - Fork 45
/
simple.survey.tool.php
38 lines (27 loc) · 1.63 KB
/
simple.survey.tool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/*
$ http://form.jotform.co/form/31755601191854 (Radio button example)
Result example : In 10 submissions, there are 3 different answers for question #3 : %70 Yes, %20 No, %10 Not Answered
$ http://form.jotform.co/form/31755930111851 (Star rating example)
Result example : In 6 submissions, there are 4 different answers for question #3 : %50 5, %16.7 1, %16.7 2, %16.7 Not Answered
1) Download JotFormAPI PHP Wrapper : https://github.com/jotform/jotform-api-php
2) Set your apiKey at line 17 (Need one? http://www.jotform.com/myaccount/api)
3) Set your formID and your question ID to get your answers' percentages
*/
include "JotForm.php";
function getSummary($formID, $questionID) {
$jotform = new JotForm("yourAPIKey");
$submissions = $jotform->getFormSubmissions($formID);
foreach($submissions as $id => $submissionDetails) {
$answer = (isset($submissionDetails["answers"][$questionID]["answer"]) && $submissionDetails["answers"][$questionID]["answer"] != "" ) ? $submissionDetails["answers"][$questionID]["answer"] : "Not Answered";
$answersArray[$answer] = isset($answersArray[$answer]) ? $answersArray[$answer] + 1 : 1;
}
$result = "";
arsort($answersArray);
foreach ($answersArray as $key => $value) {
$percentages[$key] = round(($answersArray[$key]*100) / count($submissions),1);
$result .= "%${percentages[$key]} $key, ";
}
return sprintf("In %d submissions, there are %d different answers for question #%d : %s \n ",count($submissions),count($answersArray),$questionID,trim($result,' ,'));
}
print getSummary(yourFormID, yourQuestionID);