1

I'm needing to get the unique entry submission amount for a value.

Example: Item1, Item2, Item1, Item3, Item1

Would return: 3

I was able to use the workaround here Search/Filter Freeform submissions by field value to get the specific submission amount but only wanting to know the number of unique submission values.

Can anyone help?

2 Answers 2

1

Looks like there's a Craft 2 plugin that exposes PHP's array_unique method to Twig.

So to continue on the example you linked to, it would be something like this with that plugin installed:

{# Initiate the hash in which we'll store matching submissions. #}
{% set matchingSubmissions = [] %}

{#
    Loop through all submissions, checking if the specified field
    matches the desired value.
#}
{% for submission in submissions if submission.fieldWithValue == '123' %}

    {# If the field matches, add it to the hash #}
    {% set matchingSubmissions = matchingSubmissions|merge([submission.fieldWithValue]) %}

{% endfor %}

{# Count the size of the resulting hash and save it. #}
{% set totalUniques = matchingSubmissions|unique|length %}
1

You could also add andWhere to your query. Look to the table 'freeform_fields' for the field who you want to use for the query end remember the id of the field. In the table 'freeform_submissions' look to the field names an look to field_[rememberd_id]

field__21 is in my case a hidden field for an entryId to show all submissions related to an entry.

for example:

{% set submissions = craft.freeform.submissions({
    form: 'formName',
    status: ["open"],
}).andWhere('field_21 =' ~ entry.id) %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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