{% load i18n sekizai_tags cms_tags %}

<form method="post" role="form"
    {% if form.is_multipart %}enctype="multipart/form-data"{% endif %}
    class="aldryn aldryn-forms{% block form_classes %}{% if instance.custom_classes %} {{ instance.custom_classes }}{% endif %}{% endblock form_classes %}">
    {% csrf_token %}
    {% for field in form.hidden_fields %}{{ field }}{% endfor %}

    {% if form.non_field_errors %}
        <div class="alert alert-danger" role="alert">
            {% for error in form.non_field_errors %}
                <p>{{ error }}</p>
            {% endfor %}
        </div>
    {% endif %}

    {% if form_success_url %}
        <div class="alert alert-success" role="alert">
            <p>{% blocktrans %}Thank you for submitting your information, you will be <a href="{{ form_success_url }}">redirected shortly</a>.{% endblocktrans %}</p>
        </div>
    {% endif %}

    {% if not form_success_url %}
        {% for plugin in instance.child_plugin_instances %}
            {% render_plugin plugin %}
        {% endfor %}
    {% endif %}
</form>


{# INFO: this hack is currently required because we can't redirect from a plugin. #}
{% if form_success_url %}
{% addtoblock "js" %}
<script>
setTimeout(function () {
    window.location.href = '{{ form_success_url }}';
}, 2000);
</script>
{% endaddtoblock %}
{% endif %}
