Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

Can't get form to work on my page

first-time form theme

Started by dstechit 6 days ago · 7 replies · 178 views
6 days ago

Hello everyone,

I’m currently trying to implement a contact form on my website, but I’m running into several issues and can’t seem to get it working properly.

I’ve already tried multiple approaches and even asked tools like Claude and ChatGPT, but unfortunately I haven’t found a solution yet.

The main problems are:

  • I can’t get the theme to work correctly with the form
  • The form does not process requests as expected
  • When I submit the form, I receive the following error message:
    "Call to undefined method RuntimeException::getMessages()"

As I’m still quite new to programming, I might be overlooking something basic.

Does anyone have an idea what could be causing this or how to fix it?

Thanks a lot in advance!

Contents of form.md:

YAML
---
title: 'Kontakt'
template: kontakt
description: 'contact me'
form:
    name: kontaktformular

    fields:
        vorname:
          label: Vorname
          type: text
          validate:
            required: true

        nachname:
          label: Nachname
          type: text
          validate:
            required: true

        email:
          label: E-Mail
          type: email
          validate:
            required: true

        telefon:
          label: Telefon
          type: text

        nachricht:
          label: Nachricht
          type: textarea
          validate:
            required: true

    buttons:
        submit:
          type: submit
          value: Absenden

    process:
        email:
            subject: "Neue Kontaktanfrage von {{ form.value.vorname|e }} {{ form.value.nachname|e }}"
            body: "{% include 'forms/data.html.twig' %}"
        message: 'Danke für deine Nachricht!'
        reset: true
---

# Kontakt

Contents of kontakt.html.twig:

HTML
{% extends 'partials/base.html.twig' %}

{% block content %}
<section class="page-hero">
    <div class="container" data-aos="fade-up">
        <h1>Kontakt</h1>
        <p>Wir freuen uns auf Ihre Nachricht</p>
    </div>
</section>

<section class="kontakt-section">
    <div class="container">
        <div class="kontakt-grid">
            <div class="kontakt-info" data-aos="fade-right">
                <h2>Kontaktdaten</h2>
                <div class="info-item">
                    <span class="info-icon">🏢</span>
                    <div>
                        <strong>COMPANY</strong>
                        <p>NAME</p>
                    </div>
                </div>
                <div class="info-item">
                    <span class="info-icon">📍</span>
                    <div>
                        <strong>Adresse</strong>
                        <p>STREET<br>TOWN</p>
                    </div>
                </div>
                <div class="info-item">
                    <span class="info-icon">📞</span>
                    <div>
                        <strong>Telefon</strong>
                        <p><a href="tel:0123456">0123456</a></p>
                    </div>
                </div>
                <div class="info-item">
                    <span class="info-icon">✉️</span>
                    <div>
                        <strong>E-Mail</strong>
                        <p><a href="mailto:[email protected]">[email protected]</a></p>
                    </div>
                </div>
            </div>
            <div class="kontakt-form" data-aos="fade-left">
                    {{ forms(page.header.form).render()|raw }}
            </div>
        </div>
    </div>
</section>

{% endblock %}
last edited 07/07/26 by dstechit
6 days ago

Questions first:

Notes:

  • Beware to use proper/consistent indentation in yaml.
  • No need to create your own "kontakt" template. There already is a form template.
  • Instead of setting the template name in the header of a page (which is not wrong), it is most common to name the page file with the template name. E.g `form.md`
  • If you really need to, it should be in /templates since it is a page template and not a partial.

Suggestion:

  • Please follow the steps shown in the example contact form and see if it works for you.
last edited 07/07/26 by pamtbaau
6 days ago

I want to use the same design for the contact form that I have on my whole page... with the

TWIG
{% include "forms/form.html.twig" %}

It's a really bad looking form just rectangles i can put text in.
Not like I want with rounded corners and so on. (The example snippet also is a unformatted mess)

But then when I submit I get the descriped error.

And I also tried the other mentioned possible include into twig codes

last edited 07/07/26 by dstechit
6 days ago

I want to use the same design for the contact form that I have on my whole page...

...

It's a really bad looking form just rectangles i can put text in.

That's CSS which comes with your theme. If the theme does not provide styling for form fields, you'll get default styling, which might not be to your liking.

As said, there is no need to include {% include "forms/form.html.twig" %} in your custom template. The form plugin already provides a good template.

But then when I submit I get the descriped error.

To debug:

  • Remove the process.email part and see what happens.
last edited 07/07/26 by pamtbaau
6 days ago

As said, there is no need to include {% include "forms/form.html.twig" %} in your custom template. The form plugin already provides a good template.

But how do get the form displayed... my page is built only in the twig file?

To debug:

Remove the process.email part and see what happens.

I will do that and get you updated

6 days ago

But how do get the form displayed...

By naming your page form.md en remove the template: kontakt from the header of the page. The Form plugin and Grav together will create for you a page automagically with the text in de page on top and the form at the bottom.

You might want to read the docs on Forms to educatie yourself.

6 days ago

I read the docs an I have a fairly designed form now.

But gain with the same problem:
Call to undefined method RuntimeException::getMessages()

I have removed the process from the form.. still the same

6 days ago

Using a fresh install of the latest Grav 2.x, I cannot reproduce the issue:

  • Used your form, in a form.md page
  • Removed template: kontakt from header
  • Submitted form
  • Thank you message is shown
  • Received email

Questions:

last edited 07/07/26 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Support · by BenLaKnet, 5 days ago
1 116 2 days ago
Support · by BenLaKnet, 1 week ago
5 193 2 days ago
Support · by kskt, 2 days ago
0 42 2 days ago
Support · by David Meissner, 2 days ago
0 38 2 days ago
Support · by David Meissner, 3 days ago
3 88 3 days ago