{% macro render_form(form, legend=None, child=False) %}
    {% if not child %}
        {{ form.csrf_token }}
        {% if form.csrf_token.errors %}
            <ul class="errors">
                {% for error in form.csrf.errors %}<li>{{ error }}{% endfor %}
            </ul>
        {% endif %}
    {% endif %}
    <fieldset>
        {% if legend %}<h2>{{ legend }}</h2>{% endif %}
        {% for field in form %}
            {% if field.widget.__class__.__name__ == "HiddenInput" %}
                {{ field }}
            {% elif field.type == "FormField" %}
                </fieldset>
                {{ render_form(field, field.label.text, True) }}
                {% if not loop.last %}<fieldset>{% endif %}
            {% else %}
                {% if field.errors %}
                    <ul class="errors">
                        {% for error in field.errors %}<li>{{ error }}{% endfor %}
                    </ul>
                {% endif %}
                <p id="{{field.name}}_holder" class="field{% if field.errors %} error{% endif %}{% if field.flags.required %} required{% endif %}">
                    {{ field.label }}
                    {{ field }}
                </p>
            {% endif %}
        {% endfor %}
    {% if not child %}</fieldset>{% endif %}
{% endmacro %}
