Add contact form with reCAPTCHA, saved to DB, viewable in admin

Adds a public /contact page (name/email/message, protected by the same
reCAPTCHA v3 setup used on registration) that persists submissions to
a new contact_message table, plus a Contact section in the admin panel
to read them. Linked from the site footer.
This commit is contained in:
Frank
2026-08-29 11:11:06 +02:00
parent fd8d1730e8
commit 6fb3ed597b
12 changed files with 317 additions and 0 deletions
+1
View File
@@ -136,6 +136,7 @@
{ route: 'game_admin_games', label: 'Games', icon: '🎮' },
{ route: 'game_admin_sessions', label: 'Sessions', icon: '▶' },
{ route: 'game_admin_feedback', label: 'Feedback', icon: '💬' },
{ route: 'game_admin_contact', label: 'Contact', icon: '📨' },
{ route: 'game_admin_email_log', label: 'Email Log', icon: '✉' },
] %}
@@ -0,0 +1,39 @@
{% extends 'game/admin/base.html.twig' %}
{% block title %}Contact Messages — Admin{% endblock %}
{% block admin_body %}
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem;">
<h1 style="margin: 0; font-size: 1.5rem; color: #0f172a;">Contact Messages</h1>
<span style="color: #64748b; font-size: 0.9rem;">{{ messages|length }} message{{ messages|length != 1 ? 's' : '' }}</span>
</div>
<div style="background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.07); overflow: hidden;">
<table class="admin-datatable" style="width: 100%; min-width: 760px; border-collapse: collapse; font-size: 0.9rem;">
<thead>
<tr style="background: #f1f5f9; border-bottom: 1px solid #e2e8f0;">
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Received</th>
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Name</th>
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Email</th>
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Message</th>
</tr>
</thead>
<tbody>
{% for entry in messages %}
<tr style="border-bottom: 1px solid #f1f5f9;">
<td style="padding: 0.75rem 1rem; color: #475569; white-space: nowrap;">{{ entry.createdAt|date('Y-m-d H:i:s') }}</td>
<td style="padding: 0.75rem 1rem; font-weight: 500; color: #0f172a;">{{ entry.name }}</td>
<td style="padding: 0.75rem 1rem; color: #475569;">
<a href="mailto:{{ entry.email }}" style="color: #3b82f6; text-decoration: none;">{{ entry.email }}</a>
</td>
<td style="padding: 0.75rem 1rem; color: #475569; max-width: 480px; white-space: pre-wrap;">{{ entry.message }}</td>
</tr>
{% else %}
<tr>
<td colspan="4" style="padding: 2rem; text-align: center; color: #94a3b8;">No messages yet.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
+2
View File
@@ -67,6 +67,8 @@
<footer class="site-footer py-4">
<div class="container text-center small">
<div class="mb-1">
<a href="{{ path('website_contact') }}" class="link-light">{{ 'footer.contact'|trans }}</a>
&middot;
<a href="{{ path('website_help_wanted') }}" class="link-light">{{ 'footer.help_wanted'|trans }}</a>
&middot;
<a href="{{ path('website_terms') }}" class="link-light">{{ 'footer.terms'|trans }}</a>
+31
View File
@@ -0,0 +1,31 @@
{% extends 'layout/site.html.twig' %}
{% block title %}Contact | {{ 'site.name'|trans }}{% endblock %}
{% block body %}
<div class="row justify-content-center">
<div class="col-lg-7">
<div class="text-center mb-4">
<h1 class="display-6 fw-bold">Contact</h1>
<p class="lead text-secondary">Got a question, a bug to report, or just want to say hi?</p>
</div>
<div class="card shadow-sm">
<div class="card-body">
{{ form_errors(contactForm) }}
{{ form_start(contactForm) }}
{{ form_row(contactForm.name) }}
{{ form_row(contactForm.email) }}
{{ form_row(contactForm.message) }}
{{ form_row(contactForm.captcha) }}
<div class="d-grid mt-3">
<button type="submit" class="btn btn-primary">Send Message</button>
</div>
{{ form_end(contactForm) }}
</div>
</div>
</div>
</div>
{% endblock %}