I’m trying to figure out how to specify the output of a form.
The standard output is enough for the configured emailaddress, but for the form-email i want a different format with output. How do i do this?
- email:
from: "{{ config.plugins.email.from }}"
to:
- "{{ config.plugins.email.from }}"
- "{{ form.value.email }}"
subject: "[Aanmeldformulier] {{ form.value.name|e }}"
body: "{% include 'forms/data.html.twig' %}"```
I need to figure out how to specify a second body/subject for {{ form.value.email }}.
Test the template by filling out the contact form. You should receive a customize message containing the contact’s info. Verify and tweak however you want the body of the email to read.
@SjoerdSmeets It might be worth considering to rephrase the question and explaining what you do look for…
After some pondering… Do you perhaps mean that you want to send two different emails, each with its own to/subject/body? One to yourself and one to {{ form.value.email }}?
I have no hands-on experience with the Email plugin, but have you tried splitting the email action into two separate actions? One to yourself and one to the client each with their own to/subject/body?
@SjoerdSmeets With some help of the Form docs, albeit a bit hidden I have to admit… The following seems to be doing what you are looking for.
Note: I used a fresh install of Grav 1.6.0-beta.6 with Quark and an inherited theme.
Create a new page with a contact form:
user/pages/03.contact/
form.md
Add the following frontmatter with two separate email actions:
---
title: Contact Form
form:
name: contact
fields:
- name: name
label: Name
placeholder: Enter your name
autocomplete: on
type: text
validate:
required: true
- name: email
label: Email
placeholder: Enter your email address
type: email
validate:
required: true
- name: message
label: Message
placeholder: Enter your message
type: textarea
validate:
required: true
buttons:
- type: submit
value: Submit
- type: reset
value: Reset
process:
- email:
# To myself
to: "{{ config.plugins.email.to }}"
subject: "Email to myself"
- email:
# To visitor
# Using defaults for 'to' and 'from'
subject: "Email to visitor"
body: "{% include 'forms/visitor.html.twig' %}" <-- a custom template
---
# Contact form
Some sample page content
In your inherited theme create a new Twig template ‘users/themes/mytheme/templates/forms/visitor.html.twig’. Add the following content:
<p>This is the body for the visitor's email based on template "forms/data.html.twig"
which can be found in folder "/user/plugins/form/templates/forms/".</p>;
{% include "forms/data.html.twig" %}