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.

Forms & Blueprints

Modular form error validation

Started by Duc 8 years ago · 0 replies · 821 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 Ton Haarmans, 5 years ago
13 1144 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 138 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 114 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 132 7 months ago