I need help making a contact form

I’m stumped (no surprise)!

I copied the code directly from here

---
title: Contact Form

form:
    name: contact

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

        email:
          label: Email
          placeholder: Enter your email address
          type: email
          validate:
            required: true

        message:
          label: Message
          placeholder: Enter your message
          type: textarea
          validate:
            required: true

        g-recaptcha-response:
          label: Captcha
          type: captcha
          recaptcha_not_validated: 'Captcha not valid!'

    buttons:
        submit:
          type: submit
          value: Submit
        reset:
          type: reset
          value: Reset

    process:
        captcha: true
        save:
            fileprefix: contact-
            dateformat: Ymd-His-u
            extension: txt
            body: "{% include 'forms/data.txt.twig' %}"
        email:
            subject: "[Site Contact Form] {{ form.value.name|e }}"
            body: "{% include 'forms/data.html.twig' %}"
        message: Thank you for getting in touch!
        display: thankyou
---

# Contact form

Some sample page content

to make a contact form which can be found here and when submitted it causes an error…


Server Error
Sorry, something went terribly wrong!
0 - No secret provided


Then I took the code from here

---
title: Contact
form:
    name: my-nice-form
    fields:
        - name: name
          label: Name
          placeholder: Enter your name
          autofocus: on
          autocomplete: on
          type: text
          validate:
            required: true

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

        - name: message
          label: Message
          size: long
          placeholder: Enter your message
          type: textarea
          validate:
            required: true

    buttons:
        - type: submit
          value: Submit
          classes: gdlr-button with-border excerpt-read-more

    process:
        - email:
            from: "{{ config.plugins.email.from }}"
            to:
              - "{{ config.plugins.email.from }}"
              - "{{ form.value.email }}"
            subject: "[Feedback] {{ form.value.name|e }}"
            body: "{% include 'forms/data.html.twig' %}"
        - save:
            fileprefix: feedback-
            dateformat: Ymd-His-u
            extension: txt
            body: "{% include 'forms/data.txt.twig' %}"
        - message: Thank you for your feedback!
        - display: thankyou
---

to make another contact form which can be found here and when submitted it indicates it was successful, however no email is ever received.

I’ve edited user/plugins/email/email.yaml to include my email addresses in the to/from fields just to test things and nothing is received…

enabled: true
from: my-actual-email-address
to: my-actual-email-address
mailer:
  engine: sendmail
  smtp:
    server: localhost
    port: 25
    encryption: none
    user:
    password:
  sendmail:
    bin: '/usr/sbin/sendmail -bs'
content_type: text/html

@Alpha,

I’m stumped

So am I…

Please help the community help you by spending a tad more time and effort on the question. It would be more helpful:

  • If you could share the actual code snippet you used in your page, instead of pointing to the original. You might have made a mistake…
  • If you could share all the steps you’ve performed to create the form.
    To get the form running, it requires more than just copying the code snippet into the form.md file…
  • If you could share the exact error message you are receiving
  • If you could confirm you have setup and tested the email plugin.

Update: Thanks for updating your post.

@Alpha,

First form:

  • You probably haven’t configured reCaptcha and/or added the site-key and secret-key to the config of the form plugin as mentioned in the page where you copied the code snippet from.

Second form:

  • user/plugins/email/email.yaml
    Do not ever edit the config files inside a plugin itself, but instead in /user/config/plugins/email.yaml. If you do, your config will be lost when the plugin gets updated.
  • The config for the email plugin doesn’t seem ok. Please contact your provider for correct settings like server, port, encryption… Then test it as mentioned before.
1 Like