1

I am using freeform to manage forms on my site.

I'd like to limit the number of entries on a form to 200 per day.

The method I thought would be best is to get the submissions for the form, and use the dateCreated parameter to only return those that matched today's date.

Here's my code

{% set form = entry.form %}
{% set submissions = craft.freeform.submissions({
    form: form.handle,
    dateCreated: 'now' | date('d M Y')
}) %}

{{ submissions | length }}

But it isn't working. Am I getting the date parameter wrong?

2 Answers 2

1

I managed to get this working in the end. Here is my final code;

{# Calculate entries per day #}
{% set form = entry.form %}
{% set todaysEntriesIndex = 0 %}
{% set submissions = craft.freeform.submissions({
    form: form.handle
}).all() %}

{# Count each submission from the day #}
{% for submission in submissions %}
    {% if submission.dateCreated | date('d/m/Y') == 'now' | date('d/m/Y') %}
        {% set todaysEntriesIndex = todaysEntriesIndex + 1 %}
    {% endif %}
{% endfor %}

Once this has been setup you can use the following to check the amount:

 todaysEntriesIndex >= 200
1
  • After running this for a few weeks, it works, but becomes poorly performant the more entries you have (as you've search through each entry). You can always set your limit in the submissions call to limit it to the number you are looking for. Commented Jan 15, 2020 at 11:04
1

Wouldn't it be smarter to create a new invisible field and add it to the relevant form and then dynamically fill it in with the date in the front-end template.

This way you could filter submissions via custom fields. As below:

{% set submissions = craft.freeform.submissions({
  fieldSearch: {
    yourDateField: 'now'|date('d M Y')
  }
}) %}

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.