{% extends "demo/_layout" %}

{% set pageTitle = "Checking Submission Duplicates | Extras" %}

{# Replace 'freeformSubmissionDuplicate' with your form handle #}
{% set demoFormHandle = "freeformSubmissionDuplicate" %}

{% block content %}

    {% set form = craft.freeform.form(demoFormHandle, { formattingTemplate: pageTemplateFile }) %}

    <div class="freeform-page-heading">
        <h2>Checking Submission Duplicates</h2>
        <p>This example shows how to check if the user has already submitted the form when using the <i>Limit Form Submission Rate</i> setting.</p>
    </div>

    {% if form and form.limitFormSubmissions %}
        
        {# This optional conditional checks if the form has reached its submission limit set above #}
        {% if form.submissionLimitReached %}

            <div class="freeform-error">
                <h4>{{ "Already Submitted!" }}</h4>
                <p>
                    You have already submitted this form! No duplicates are allowed for this form.
                </p>
            </div>

        {% else %}

            {% if form.limitFormSubmissions %}
            {# Display a tip for forms with submit limit setting enabled #}
                <div class="freeform-notice">
                    <h4>Please note...</h4>
                    <p>
                        You currently have a user submit limit setting enabled (<i>
                            {%- if form.limitFormSubmissions == "auth_unlimited" -%}
                                Logged in Users only (no limit)
                            {%- elseif form.limitFormSubmissions == "cookie" -%}
                                Once per Cookie
                            {%- elseif form.limitFormSubmissions == "ip_cookie" -%}
                                Once per IP/Cookie combo
                            {%- elseif form.limitFormSubmissions == "auth" -%}
                                Once per logged in Users
                            {%- elseif form.limitFormSubmissions == "auth_cookie" -%}
                                Once per logged in User or Guest Cookie
                            {%- elseif form.limitFormSubmissions == "auth_ip_cookie" -%}
                                Once per logged in User or Guest IP/Cookie combo
                            {%- elseif form.limitFormSubmissions == "once_per_email" -%}
                                Once per Email Address only
                            {%- else -%}
                                '{{ form.limitFormSubmissions }}'
                            {%- endif -%}
                        </i>) for this form.
                    </p>
                </div>
            {% endif %}

            {{ form.render }}

        {% endif %}

    {% else %}

        <div class="freeform-error">
            <p>You must rename your form handle to <code>{{ demoFormHandle }}</code> and set a limit (<i>Limit Form Submission Rate</i> setting inside the <i>Validation</i> tab in the form builder) for this part of the demo to work.</p>
        </div>

    {% endif %}

    {# Instructions to get this page working correctly #}
    <div class="extras-instructions">
        <h4>This page will not display correctly until...</h4>
        <p>
            In order to view this page live, you'll need to make some adjustments to this template or your test form:
            <ol>
                <li>Rename your test form handle to <code>{{ demoFormHandle }}</code> or adjust the form handle name inside this template to match your test form.</li>
                <li>
                    Make sure you have the <b>Limit Form Submission Rate</b> setting enabled (inside the <i>Validation</i> tab in the form builder).
                </li>
                <li>This page template contains a conditional that will hide the form once it detects that the user has already submitted the form.</li>
            </ol>
        </p>
    </div>

{% endblock %}