Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Userforms - Sorting fields in CSV export

Go to End

3 Posts   2286 Views


Community Member, 323 Posts

23 October 2009 at 3:47am


When exporting the submissions of an user form to a CSV file, the order of the fields is not respected, I guess they are ordered by creation date or so… How can I get those CSV columns properly ordered? It baffles me since a <% control Fields %> outputs fields in the desired order.

Thanks in advance,


Community Member, 130 Posts

17 March 2010 at 4:05pm

Hi Juan,

I realise this is an old post but I had the same problem and hopefully this will help someone else.

I changed the SQL statement on line 89 of SubmittedFormReportField.php from

$tmp = DB::query("SELECT DISTINCT `Name`, `Title` FROM `SubmittedFormField` LEFT JOIN `SubmittedForm` ON `SubmittedForm`.`ID` = `SubmittedFormField`.`ParentID` WHERE `SubmittedFormField`.`ParentID` IN (" . implode(',', $inClause) . ") ORDER BY `SubmittedFormField`.`ID`")


$tmp = DB::query("SELECT DISTINCT `Name` , `Title` FROM ( (SELECT `Name` , `Title` FROM `SubmittedFormField` LEFT JOIN `SubmittedForm` ON `SubmittedForm`.`ID` = `SubmittedFormField`.`ParentID` IN (" . implode(',', $inClause) . ") ORDER BY `SubmittedFormField`.`ID`) AS `tmp` )")

It basically forces the ordering to happen before the table is reduced with the distinct command - apparently DISTINCT and ORDER BY don't work well together.


Community Member, 89 Posts

8 October 2010 at 1:11pm

Hi guys,

This has been included in changeset. JonoM, I've used your query, but modified it so the most recent submission ordering takes precedence. Would be nice if someone could cross-check it :)