File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 165
165
})->name ('getFormResponses ' );
166
166
167
167
168
+ // /form/responses/:id_form/download/ controller
169
+ // Download responses as csv format
170
+
171
+ // We create the csv files on the fly
172
+
173
+ $ app ->get ('/form/responses/:id_form/download ' , function ($ id_form ) use ($ app ) {
174
+
175
+ $ c = array ();
176
+
177
+ // We grab the form
178
+ $ form = models \Form::find ($ id_form );
179
+
180
+ // We grab its fields (will be referenced by their ids on the responses)
181
+ $ fields = $ form ->fields ;
182
+
183
+ // We grab its responses
184
+ $ responses = models \ModelBuilder::fromTable ('responses_ ' .$ id_form )->all ();
185
+
186
+ $ c ['responses ' ] = $ responses ;
187
+ $ c ['fields ' ] = $ fields ;
188
+
189
+ $ app ->response ()->header ('Content-Type ' , 'text/csv ' );
190
+ $ app ->response ()->header ('Content-Disposition ' , 'attachment;filename=form ' .$ id_form .'_export.csv ' );
191
+
192
+ $ app ->render ('pages/csv.html ' , $ c );
193
+
194
+ })->name ('getFormResponsesDownload ' );
195
+
196
+
168
197
169
198
// /form/responses/:id_form/delete/:id_response controller
170
199
// Delete responses associated to a form
182
211
})->name ('getFormResponseDelete ' );
183
212
184
213
214
+
215
+
216
+
217
+
218
+
185
219
/*
186
220
* POST CONTROLLERS
187
221
*/
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ <h3>Form details - <a href="{{ base_path }}/index.php/form/edit/{{ form.id }}">E
27
27
28
28
</ dl >
29
29
30
- < h3 > Form responses</ h3 >
30
+ < h3 > Form responses - < a href =" {{ base_path }}/index.php/form/responses/{{ form.id }}/download " > Download as csv </ a > </ h3 >
31
31
32
32
{% for r in responses %}
33
33
< div class ="row ">
You can’t perform that action at this time.
0 commit comments