Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Modular form error validation

Started by Duc 8 years ago · 0 replies · 1037 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 Japhy, 2 weeks ago
2 275 4 days ago
Forms & Blueprints · by FrViPofm, 4 weeks ago
5 330 4 weeks ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2322 8 months ago
Forms & Blueprints · by Hugo Oliveira, 9 months ago
0 782 9 months ago
Forms & Blueprints · by Flachy Joe, 10 months ago
9 871 10 months ago