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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Issue using form with email plugin

form plugins

Started by Alberto 1 year ago · 1 replies · 89 views
1 year ago

Hi there!

I'm trying to build a contact form and though i tried to follow docs, it seems I'm still missing something.
On my server I have postfix installed with all the needed certificates to send emails.
If i run this command sudo bin/plugin email test-email -t <my-email> I receive it.
But if I fill the grav form and submit, it seems the service doesn't even get called.

This is my email plugin configuration:

YAML
enabled: true
from: <my-domain>
to: <my-email>
mailer:
  engine: smtp
  smtp:
server: <my-server-ip>
    port: 25
    encryption: none
    user: null
    password: null
  sendmail:
    bin: "/usr/sbin/sendmail -bs"
content_type: text/html
debug: true
cc: null
bcc: null
reply_to: null
body: null

and this is my contact form frontmatter

YAML
---
title: Contact us
cache_enable: false
description: Feel free to reach out! We’ll get back to you as soon as possible.
template: partials/components/form-contact-us
process:
  twig: true
  markdown: false

form:
  action: /contacts
  name: contact_form

  fields:
    - name: name
      label: Name
      type: text
      placeholder: Enter your name
      validate:
        required: true

    - name: surname
      label: Surname
      type: text
      placeholder: Enter your surname
      validate:
        required: true

    - name: email
      label: Email
      type: email
      placeholder: Enter your email
      validate:
        required: true

    - name: message
      label: Message
      type: textarea
      placeholder: Enter your message
      validate:
        required: true
        min: 10

  buttons:
    - type: submit
      value: Send

  process:
    email:
      - from: "{{ config.plugins.email.from }}"
        to: "{{ config.plugins.email.to }}"
        subject: "New Message from {{ form.value.name|e }} {{ form.value.surname|e }}"
        body: |
          Hi,
          You have received a new message.

          **Name:** {{ form.value.name|e }}
          **Surname:** {{ form.value.surname|e }}
          **Email:** {{ form.value.email|e }}
          **Message:**
          {{ form.value.message }}

    message: "Thank you for getting in touch!"
    reset: true
---
and here is the twig template \user\themes\quark\templates\partials\components\form-contact-us.html.twig

type or paste code here

TWIG
<section class="form-contact-us-wrapper">
    <div class="form-contact-us">
        <div class="header">
            <h3>{{ module.header.title }}</h3>
            <span>{{ module.header.description }}</span>
        </div>
        <form method="post" action="{{ page.url }}">
            <ul class="controls">
                <li class="control">
                    <label for="name">{{ "NAME"|t }}</label>
                    <input type="text" id="name" name="name" placeholder="{{ "ENTER_YOUR_NAME"|t }}" required>
                </li>
                <li class="control">
                    <label for="surname">{{ "SURNAME"|t }}</label>
                    <input type="text" id="surname" name="surname" placeholder="{{ "ENTER_YOUR_SURNAME"|t }}" required>
                </li>
                <li class="control">
                    <label for="email">{{ "EMAIL"|t }}</label>
                    <input type="email" id="email" name="email" placeholder="{{ "ENTER_YOUR_EMAIL_ADDRESS"|t }}" required>
                </li>
                <li class="control">
                    <label for="message">{{ "MESSAGE"|t }}</label>
                    <textarea id="message" name="message" placeholder="{{ "ENTER_YOUR_MESSAGE"|t }}" required minlength="10"></textarea>
                </li>
            </ul>

            <button type="submit" title="{{ "SEND"|t }}">{{ "SEND"|t }}</button>
        </form>
    </div>
</section>

1 year ago

@bebiuz, You should not create a custom template. The Form plugin will take care of it. The email process action defined in the form definition will redirect data from the form to the Email plugin.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 42 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 47 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 71 2 months ago