Contact form disappearing randomly

Hi all,

From every few days (sometimes a couple of times a day) a contact form on my website disappears. As in, the HTML to render the form components does not seem to be generated. When I view the source, all the code for the form is missing.

This is what I keep seeing:

and this is how it should appear:

I cannot work out what is causing the form component to not render. I’m not making changes to the website on a daily basis, but I have to keep checking on it to make sure the contact form is still available.

This form is supposed to render at the bottom of every page on the site, and when it’s not working no matter what page you’re on the form will be invisible. I have another form that appears on just a single page, and I’ve not had any problems with that form. I feel this could be a clue as to why the form shown in the footer of every page could be misbehaving.

The really weird thing is that the only way I can get the form to reappear is by saving the file user/config/system.yaml (full file included at the bottom of this post). I don’t have to make any changes to the file, but if I just save it (thus updating the modified timestamp) then refresh my site in a browser, the footer contact form is again visible.

I get the footer contact form to render on each page of the site by defining the form in the following page:

user/pages/contact-form-hidden-definition/default.md

---
title: 'Contact Form Definition (Hidden)'
cache: false
form:
    name: contact-form
    classes: null
    fields:
        -
            name: name
            id: name
            label: 'Your name'
            labelclasses: sr-only
            placeholder: 'Your name (required)'
            outerclasses: form-group
            classes: form-control
            wrapper_classes: null
            autocomplete: 'on'
            type: text
            validate:
                required: true
        -
            name: email
            id: email
            label: 'Your email address'
            labelclasses: sr-only
            placeholder: 'Your email address (required)'
            outerclasses: form-group
            classes: form-control
            wrapper_classes: null
            type: email
            validate:
                required: true
        -
            name: phone
            id: phone
            label: 'Your phone number'
            labelclasses: sr-only
            placeholder: 'Your phone number'
            outerclasses: form-group
            classes: form-control
            wrapper_classes: null
            type: tel
        -
            name: message
            id: message
            label: 'Your message'
            labelclasses: sr-only
            size: long
            placeholder: 'Your message (required)'
            outerclasses: form-group
            classes: form-control
            wrapper_classes: null
            rows: 5
            type: textarea
            validate:
                required: true
        -
            name: g-recaptcha-response
            id: g-recaptcha-response
            label: Catcha
            labelclasses: sr-only
            type: captcha
            recaptcha_not_validated: 'Captcha not valid!'
            outerclasses: form-group
            classes: form-control
            wrapper_classes: null
            validate:
                required: true
    buttons:
        -
            type: submit
            value: Submit
            classes: 'btn btn-primary'
    process:
        -
            captcha: null
        -
            email:
                to: '{{ config.plugins.email.to }}'
                from: '{{ config.plugins.email.from }}'
                reply_to: '{{ form.value.email }}'
                subject: 'Website Message: {{ form.value.name|e }}'
                body: '{% include "partials/contact-form/data.html.twig" %}'
        -
            email:
                to: '{{ form.value.email }}'
                from: '{{ config.plugins.email.from }}'
                reply_to: '{{ config.plugins.email.from }}'
                subject: 'Message received'
                body: '{% include "partials/contact-form/data-confirmation.html.twig" %}'
        -
            save:
                fileprefix: feedback-
                dateformat: Ymd-His-u
                extension: txt
                body: '{% include "partials/contact-form/data.txt.twig" %}'
        -
            message: '<h5 class="alert-heading">Thank you for your message!</h5>'
        -
            reset: true
---

The files in user/themes/mytheme/templates/partials/contact-form are all copied from the form plugin, with just one or two lines changed for personalised response messages.

The contact form is included in the footer here:

user/themes/mytheme/templates/partials/footer.html.twig

<section id="contact" class="bg-medium-dark">
  <div class="container">

    <div class="row">

      <div class="col-md-6" id="col-contact-form">
        <h3 class="mb-4">Email us</h3>

        {% include 'partials/contact-form/form.html.twig' with { form: forms('contact-form') } %}

      </div>

      ...

One thing I should note in case it’s relevant is that this is a website for my upcoming wedding and is password-protected using the login plugin. So when a visitor arrives at the site, they are presented with a box to input a password. The username is already saved as a value in the login form. (This isn’t an ideal solution, but I’d already sent out invitations with just a password on before I realised it wasn’t a straightforward job to password-protect an entire site using Grav.)

image

In trying to pin down the problem with the contact form I did try logging in and logging out of the website and seeing if the form appeared, but it didn’t make any difference.

I did have a copy of the site running on a different subdomain for testing purposes, and this generally exhibited the same problem at the same time as the live site. Because I’ve only been checking the site once per day, at random times, I’ve not been able to pin down exactly when the form has stopped working. I had debugging set to true on the testing site, but I’ve seen no errors or warnings in the log.

I’ve since deleted the testing subdomain and contents of that site, and obtained a new SSL certificate for just the primary site in case the wildcard SSL cert I was previously using was causing problems.

If anyone has got any clues about why the form disappears from time to time, I’d be so grateful to hear from you! Thanks for reading!

Chris



user/config/system.yaml

absolute_urls: false
timezone: Europe/London
param_sep: ':'
wrapped_site: false
reverse_proxy_setup: false
force_ssl: false
force_lowercase_urls: true
username_regex: '^[a-z0-9_-]{3,16}$'
pwd_regex: '(?=.*[a-z]).{7,}'
intl_enabled: true
languages:
  include_default_lang: true
  translations: true
  translations_fallback: true
  session_store_active: false
  http_accept_language: false
  override_locale: false
home:
  alias: /home
  hide_in_urls: false
pages:
  theme: mytheme
  order:
    by: default
    dir: asc
  list:
    count: 20
  dateformat:
    default: 'd-m-Y H:i'
    short: 'jS M Y'
    long: 'l jS \of F g:i A'
  publish_dates: true
  process:
    markdown: true
    twig: false
  twig_first: false
  never_cache_twig: false
  events:
    page: true
    twig: true
  markdown:
    extra: false
    auto_line_breaks: false
    auto_url_links: false
    escape_markup: false
    special_chars:
      '>': gt
      '<': lt
  types:
    - txt
    - xml
    - html
    - htm
    - json
    - rss
    - atom
  expires: 604800
  last_modified: false
  etag: false
  vary_accept_encoding: false
  redirect_default_route: false
  redirect_default_code: '302'
  redirect_trailing_slash: true
  ignore_files:
    - .DS_Store
  ignore_folders:
    - .git
    - .idea
  ignore_hidden: true
  url_taxonomy_filters: true
  frontmatter:
    process_twig: false
    ignore_fields:
      - form
      - forms
cache:
  enabled: true
  check:
    method: file
  driver: auto
  prefix: g
  clear_images_by_default: true
  cli_compatibility: false
  lifetime: 604800
  gzip: true
  allow_webserver_gzip: true
twig:
  cache: true
  debug: true
  auto_reload: true
  autoescape: false
  undefined_functions: true
  undefined_filters: true
  umask_fix: false
assets:
  css_pipeline: false
  css_pipeline_include_externals: true
  css_pipeline_before_excludes: true
  css_minify: true
  css_minify_windows: false
  css_rewrite: true
  js_pipeline: false
  js_pipeline_include_externals: true
  js_pipeline_before_excludes: true
  js_minify: true
  enable_asset_timestamp: false
  collections:
    jquery: 'system://assets/jquery/jquery-2.x.min.js'
errors:
  display: 1
  log: true
debugger:
  enabled: false
  shutdown:
    close_connection: true
  twig: true
images:
  default_image_quality: 85
  cache_all: false
  cache_perms: '0755'
  debug: false
  auto_fix_orientation: false
media:
  enable_media_timestamp: false
  auto_metadata_exif: false
  upload_limit: 26214400
session:
  enabled: true
  initialize: true
  timeout: 1800
  name: grav-site
  secure: false
  httponly: true
  split: true
gpm:
  releases: stable
  method: auto
  verify_peer: true
  official_gpm_only: true
strict_mode:
  yaml_compat: true
  twig_compat: true

1 Like

Shouldn’t that cache: false in the FrontMatter be cache_enable: false?

Ah, yes, of course! Thanks!

Unfortunately that hasn’t fixed the issue :frowning:

I have the same problem. Can help anybody?

Have this issue been resolved? I’m experiencing the very same bug here. If I clean the Cache, the form reappears for a few hours and goes away again. I did turn off the cache within the contact pages, still does it.

I had this as well, but am not sure if my issue was the same.

My form was generated from within a plugin, via twig essentially. Although this looked like a caching issue, it wasn’t actually. I don’t understand all the fine details, but twig output is cached a little differently than page output. Apart from caching, I had to make sure my twig gets executed each time. Here you have my front-matter that made it working for me. YMMV.

never_cache_twig: true
process:
    twig: true
1 Like