Display errors on invalid forms

It will probably need a bit of styling…
This commit is contained in:
Bat
2018-07-06 19:29:36 +02:00
parent 153400959c
commit 5f3afe900f
12 changed files with 68 additions and 39 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
{{ "New blog" | _ }}
@@ -7,8 +8,8 @@
{% block content %}
<h1>{{ "Create a blog" | _ }}</h1>
<form method="post">
<label for="title">{{ "Title" | _ }}</label>
<input type="text" id="title" name="title" />
{{ macros::input(name="title", label="Title", errors=errors, form=form) }}
<input type="submit" value="{{ "Create blog" | _ }}"/>
</form>
{% endblock content %}
+9
View File
@@ -21,3 +21,12 @@
</p>
</div>
{% endmacro post_card %}
{% macro input(name, label, errors, form, type="text") %}
<label for="{{ name }}">{{ label | _ }}</label>
{% if errors is defined and errors[name] %}
{% for err in errors[name] %}
<p class="error">{{ err.message | _ }}</p>
{% endfor %}
{% endif %}
<input type="{{ type }}" id="{{ name }}" name="{{ name }}" value="{{ form[name] | default(value="") }}"/>
{% endmacro input %}
+11 -4
View File
@@ -7,11 +7,18 @@
{% block content %}
<h1>{{ "Create a post" | _ }}</h1>
<form class="new-post" method="post">
<input type="text" class="title" name="title" placeholder="{{ "Title" | _ }}">
<textarea name="content" placeholder="{{ "Content" | _ }}"></textarea>
{{ macros::input(name="title", label="Title", errors=errors, form=form) }}
<label for="license">{{ "License" | _ }}</label>
<input type="text" id="licence" name="license" />
<label for="{{ name }}">{{ label | _ }}</label>
{% if errors is defined and errors.content %}
{% for err in errors.content %}
<p class="error">{{ err.message | _ }}</p>
{% endfor %}
{% endif %}
<textarea name="content" placeholder="{{ "Content" | _ }}" value="{{ form.content | default(value="") }}"></textarea>
{{ macros::input(name="license", label="License", errors=errors, form=form) }}
<input type="submit" value="{{ "Publish" | _ }}" />
</form>
+2 -5
View File
@@ -10,11 +10,8 @@
<p>{{ message }}</p>
{% endif %}
<form method="post">
<label for="email_or_name">{{ "Username or email" | _ }}</label>
<input type="text" id="email_or_name" name="email_or_name" />
<label for="password">{{ "Password" | _ }}</label>
<input type="password" id="password" name="password" />
{{ macros::input(name="email_or_name", label="Username or email", errors=errors, form=form) }}
{{ macros::input(name="password", label="Password", errors=errors, form=form, type="password") }}
<input type="submit" value="{{ "Login" | _ }}" />
</form>
+5 -11
View File
@@ -1,4 +1,5 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
{{ "New Account" | _ }}
@@ -7,17 +8,10 @@
{% block content %}
<h1>{{ "Create an account" | _ }}</h1>
<form method="post">
<label for="username">{{ "Username" | _ }}</label>
<input type="text" id="username" name="username" />
<label for="email">{{ "Email" | _ }}</label>
<input type="email" id="email" name="email" />
<label for="password">{{ "Password" | _ }}</label>
<input type="password" id="password" name="password" />
<label for="password_confirmation">{{ "Password confirmation" | _ }}</label>
<input type="password" id="password_confirmation" name="password_confirmation" />
{{ macros::input(name="username", label="Username", errors=errors, form=form) }}
{{ macros::input(name="email", label="Email", errors=errors, form=form, type="email") }}
{{ macros::input(name="password", label="Password", errors=errors, form=form, type="password") }}
{{ macros::input(name="password_confirmation", label="Password confirmation", errors=errors, form=form, type="password") }}
<input type="submit" value="{{ "Create account" | _ }}" />
</form>