For some reason Sprout Forms entries will not accept the usual order by field handle setup. When I want to order the contact entries by address for instance:

{% for formEntry in craft.sproutForms.entries.formHandle('contact').order('address') %}
{% endfor %}

I get the error:

Column not found: 1054 Unknown column 'address' in 'order clause'

This field does exist. If I remove 'order', it parses the field

  • Apparently Sprout Forms has its own DB table. So not under 'craft_content' but under 'craft_sproutformscontent_contact' when the form is 'contact. Maybe that is the cause?' – noregt Jan 6 '16 at 10:08
  • Been trying it with mysql in Twig like "SELECT * FROM craft_sproutformscontent_contact ORDER BY craft_sproutformscontent_contact.field_address ASC" but I was not able to get the right syntax in twig – noregt Jan 15 '16 at 17:42

This will now work as of Sprout Forms v2.2.0:

{# Ordering #}
{% for formEntry in craft.sproutForms.entries.formHandle('contact').order('address desc') %}
{% endfor %}

{# Filtering #}
{% for formEntry in craft.sproutForms.entries.formHandle('contact').firstName('Zoe') %}
{% endfor %#}
  • I've updated, but can't test it because now it produces an error in the assets field. see my support mail – noregt Feb 5 '16 at 9:38
  • 1
    Updated to 2.2.1 and everything works like expected now :-) – noregt Feb 6 '16 at 10:39

It seams, that the columns for the form values are not part of the sql, that's why it never will work like this. Maybe it works in upcomming versions of the Sprout Forms plugin.

As a workaround you can use the SuperSort Plugin. With this plugin it's possible to sort your form entries like you need it.

Step 1 -> Download and Install SuperSort Plugin -> https://topshelfcraft.com/lagniappe/supersort Step 2 -> Filter your form entries like this:

{% set formEntries = craft.sproutForms.entries.formHandle('contact')%}    
{% set formEntriesSort = formEntries | supersort('sortAs', '{address | lower}') %}

{% for formEntry in formEntriesSort %}
   {{ formEntry.address }}<br>
{% endfor %}

Like this it should work!

  • This works! How is it that Sprout Forms entries are not part of sql? Could you explain this a bit more and why supersort does work? I'm trying to understand this... – noregt Jan 18 '16 at 11:17
  • Also what does 'sortAs' do (not explained on the plugin page)? Sorry for the basic questions. – noregt Jan 18 '16 at 11:24
  • Maybe because of better performance the SQL does not include all the fields. But normaly the plugin should add the fields automaticly if you add such a field as orderBy statement. For deeper understanding you need to analyze the code. Have you tried to contact the Sprout Form Support about this issue? Maybe it's a bug... – Tom Bauer Jan 18 '16 at 21:52
  • About the sortAs option: Like i understand*, supersort render first the given Twig-Variable (the second parameter) for all your form.address values and after it use a simple php sort (php.net/manual/en/function.sort.php) for sorting these values and the associated Array. *i did not a deep review of the plugin... – Tom Bauer Jan 18 '16 at 22:03
  • 1
    Just got an answer from the developers and it's a bug indeed. Will be fixed in the next release, thanks for the help! – noregt Jan 20 '16 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.