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?

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
  • 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. – Harry Francis Jan 15 at 11:04

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.