{% extends "demo/_layout" %}

{% set pageTitle = "Relating Submissions to Elements | Extras" %}

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

{# Replace 'freeform-test' with your Craft Entry slug #}
{% set entry = craft.entries().slug('freeform-test').one %}

{% block content %}

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

    <div class="freeform-page-heading">
        <h2>Relating Submissions to Elements</h2>
        <p>The following example will relate the newly created submission to another element (in this case a Craft Entry) via the Freeform Submission relation element field type.</p>
    </div>

    {% if entry and form %}

        <div class="freeform-notice{{ colorMode == "dark" ? " freeform-notice-dark" }}">
            <p>Craft Entry:</p>
            <h4>{{ entry.title }} <small>(#{{ entry.id }})</small></h4>
            <p>Posted on {{ entry.postDate.format('F d, Y') }}</p>
        </div>

        {# Adjust 'relations' parameter as you please #}
        {{ form.render({
            relations: {
                productReviews: entry.id,
            }
        }) }}

    {% else %}

        <div class="freeform-error{{ colorMode == "dark" ? " freeform-notice-dark" }}">
            <p>You must rename your form handle to <code>{{ demoFormHandle }}</code> and correctly load an existing Craft Entry 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 on your test from:
            <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 a Craft Entry with a slug of <code>freeform-test</code> and includes the following Craft fields at minimum, or adjust the values inside this template:
                    <ul>
                        <li>Freeform Submissions field type with a handle of <code>productReviews</code> and the <b>Sources</b> setting include the <code>{{ demoFormHandle }}</code> form.</li>
                    </ul>
                </li>
            </ol>
        </p>
    </div>

{% endblock %}