Skip to content

Commit

Permalink
Fixes for #16 (#17)
Browse files Browse the repository at this point in the history
Some restructuring, formatting improvements. Tested with Grav v1.2.4, Form v2.7.0, Email v2.6.0, and Agency v1.4.0. Users should include a '/user/pages/01.home/thankyou/formdata.md' (per https://learn.getgrav.org/forms/forms/reference-form-actions#display) to verify that mails are sent on front-end.
  • Loading branch information
OleVik authored and rhukster committed Sep 28, 2017
1 parent 0463140 commit f81c0dc
Showing 1 changed file with 59 additions and 15 deletions.
74 changes: 59 additions & 15 deletions templates/modular/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
</div>
<div class="row">

{% if form.message %}<div class="alert notices {{ form.message_color ?: 'green' }}"><p>{{ form.message }}</p></div>{% endif %}
{% if form is null %}
{% set form = grav.session.getFlashObject('form') %}
{% endif %}

{% if form.message %}
{% if form.inline_errors and form.messages %}
<div class="alert notices {{ form.message_color ?: 'green' }}"><p>{{ "FORM.VALIDATION_FAIL"|t|raw }}</p></div>
{% else %}
<div class="alert notices {{ form.message_color ?: 'green' }}"><p>{{ form.message|raw }}</p></div>
{% endif %}
{% endif %}
{% set scope = scope ?: 'data.' %}
{% set multipart = '' %}
{% set method = form.method|upper|default('POST') %}

Expand All @@ -17,27 +28,31 @@
{% endif %}
{% endfor %}

{% set action = form.action ? base_url ~ form.action : page.url %}
{% set action = form.action ? base_url ~ form.action : base_url ~ page.route ~ uri.params %}

{% if (action == base_url_relative) %}
{% set action = base_url_relative ~ '/' ~ page.slug %}
{% endif %}

<form name="{{ form.name }}"
action="{{ action }}"
method="{{ method }}"{{ multipart }}
{% if form.id %}id="{{ form.id }}"{% endif %}
{% block form_classes %}
{% if form.classes %}class="{{ form.classes }}"{% endif %}
{% endblock %}
>

{% block inner_markup_fields_start %}{% endblock %}

<div class="col-md-6">
{% for field in form.fields %}
{% if field.position == 'left' %}
{% set value = form.value(field.name) %}
<div class="form-group">
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" ignore missing %}
</div>
{% endif %}
{% endif %}
{% endfor %}
</div>
<div class="col-md-6">
Expand All @@ -47,22 +62,51 @@
<div class="form-group">
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" ignore missing %}
</div>
{% endif %}
{% endif %}
{% endfor %}
</div>

{% include "forms/fields/formname/formname.html.twig" %}

{% block inner_markup_fields_end %}{% endblock %}

{% block inner_markup_buttons_start %}
<div class="buttons">
{% endblock %}

<div class="col-lg-12 text-center">
<div class="form-group">
{% for button in form.buttons %}
<button
{% block button_classes %}
class="{{ button.classes|default('button') }}"
{% endblock %}
type="{{ button.type|default('submit') }}"
>{{ button.value|t|default('Submit') }}</button>
{% endfor %}
</div>
<div class="form-group">
{% for button in form.buttons %}
{% if button.outerclasses is defined %}<div class="{{ button.outerclasses }}">{% endif %}
{% if button.url %}
<a href="{{ button.url starts with 'http' ? button.url : url(button.url) }}">
{% endif %}
<button
{% if button.id %}id="{{ button.id }}"{% endif %}
{% block button_classes %}
class="{{ button.classes|default('button') }}"
{% endblock %}
{% if button.disabled %}disabled="disabled"{% endif %}

type="{{ button.type|default('submit') }}"

{% if button.task %}
name="task" value="{{ button.task }}"
{% endif %}
>
{{ button.value|t|default('Submit') }}
</button>
{% if button.url %}
</a>
{% endif %}
{% if button.outerclasses is defined %}</div>{% endif %}
{% endfor %}
</div>
</div>

{% block inner_markup_buttons_end %}
</div>
{% endblock %}

{{ nonce_field('form', 'form-nonce') }}
{{ nonce_field('form', 'form-nonce')|raw }}
</form>

0 comments on commit f81c0dc

Please sign in to comment.