Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Modular form error validation

Started by Duc 8 years ago · 0 replies · 1140 views
8 years ago

I am struggling to customize the contact form with the Skeleton Agency theme to work. The contact form works out-of-the-box. I am getting tons of spams emails, so I have added the honeypot, but that isn't working too well. Someone on here suggest blocking links in the textarea box.

I have added the validation pattern for not allowing links in the textarea. This works; however, the form does not give an error message. The user maybe confused thinking the form was send successfully which it did not.

snippet of my modular.md file

YAML
<...some text above>
form:
name: inquiry
action: /home
cache_enable: false
fields:
    - name: name
      label: Name
      placeholder: 'Enter your name'
      autocomplete: 'on'
      type: text
      validate:
        required: true

    - name: email
      label: Email
      placeholder: 'Enter your email'
      type: text
      validate:
        rule: email
        pattern: "^\w([\w\.+-]*[\w-])?@([\w-]+\.)+[a-z]{2,5}$"
        required: true

    - name: message
      label: Message
      size: long
      placeholder: Your message. No links.
      type: textarea
      validate:
        pattern: '^((?!https?:\/\/)(?:\R|.))*$'
        required: true
        message: No links allowed.

buttons:
    - type: submit
      value: Submit
      class: submit

process:
    - email:
        from: '{{ config.plugins.email.from }}'
        to:
          - '{{ config.plugins.email.to }}'
          - '{{ form.value.email }}'
        subject: '[Inquiry] {{ form.value.name|e }}'
        body: '{% extends ''email/base.html.twig'' %}'
    - save:
        fileprefix: inquiry-
        dateformat: Ymd-His-u
        extension: txt
        body: '{% include ''forms/data.txt.twig'' %}'
    - message: 'You will receive a reply shortly!'
    - display: thankyou

    <...some text below>

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Anna, 2 days ago
2 53 16 hours ago
Forms & Blueprints · by Anna, 3 days ago
7 82 16 hours ago
Forms & Blueprints · by Anna, 1 week ago
5 186 6 days ago
Forms & Blueprints · by TomW, 1 month ago
3 379 1 month ago
Forms & Blueprints · by Japhy, 2 months ago
2 595 2 months ago