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

Error on contact form submit after 1.6 update

form

Started by Julien Perret 7 years ago · 0 replies · 587 views
7 years ago

Hi gravists,

I recently updated a Quark based website from 1.5.x to 1.6 with a modular contact form displaying a message with an Ajax method as explained in the documentation.

The update process broke my submission with a Ooops message and I can't figure out where's the issue.

My setup is like this:

A modular "_contact" page with the minimum code:

YAML
menu: Contact
cache_enable: false

The form itself in the main modular page:

YAML
title: 'Dr DROID'
menu: Home
onpage_menu: true
body_classes: 'title-h1h2 header-dark header-transparent'
content:
    items: '@self.modular'
form:
    name: ajax-form
    action: '/home#contact'
    template: form-messages
    refresh_prevention: true
    fields:
        -
            name: sujet
            label: Sujet
            placeholder: 'Le sujet de votre message'
            type: select
            options:
                1: Information
                2: 'Demande de devis'
                3: 'Demande de rendez-vous'
                4: 'Demander un rappel'
            validate:
                required: true
        -
            name: name
            label: Nom
            placeholder: 'Entrer votre nom'
            autocomplete: 'on'
            type: text
            validate:
                required: true
        -
            name: email
            label: Email
            placeholder: 'Saisissez votre adresse email'
            type: text
            validate:
                rule: email
                required: true
        -
            name: message
            label: Message
            size: long
            placeholder: 'Votre message'
            type: textarea
            validate:
                required: true
    buttons:
        -
            type: submit
            value: Envoyer
    process:
        -
            email:
                from: '{{ config.plugins.email.from }}'
                to:
                    - '{{ config.plugins.email.to }}'
                    - '{{ 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: 'Votre message a bien été envoyé. Merci !'

And the mandatory Ajax code in the form.html.twig:

TWIG
{% set grid_size = theme_var('grid-size') %}
{% set columns = page.header.class == 'small' ? 'col-3 col-md-4 col-sm-6' : 'col-4 col-md-6 col-sm-12'  %}

<section class="section modular-contact {{ page.header.class}} bg-gray">
    <section class="container {{ grid_size }}">
                {{ page.content }}
        <div class="col-7">
            {% include "forms/form.html.twig" with { form: forms('ajax-form') } %}
        </div>
        <div class="modal-container">
            <div class="row">
                <div class="col-xs-10 col-xs-offset-1">
                     <div id="form-result"></div>
                </div>
            </div>
        </div>
    </section>
</section>

{% block bottom %}

<script>
$(document).ready(function(){
  var form = $("#ajax-form");
  form.submit(function(e) {
      e.preventDefault();

      $.ajax({
          url: form.attr("action"),
          type: form.attr("method"),
          dataType: "html",
          data: form.serialize(),
          success: function(result) {
              $("#form-result").html(result);
          },
          complete: function(result) {
              $("html, body").animate({
                  scrollTop: $("#form-result").offset().top
              }, 200);   
          }
      });
  });    
});
</script>
{% endblock %}

This code is working perfectly in my 1.5.x copy of my site but is giving me the "Ooops" error as soon as I update to 1.6 with update of all plugins.

I don't know how to track the error as I don't see anything in the log.
How can I debug this ?

EDIT 19/06: I setup a fresh GRAV site, copied the template and the data.
For the moment, with a simple form (without action, template message and AJAX), it's working. As soon as I try to add functionality, it's giving me the Oops error.
I'll investigate a bit more.

last edited 06/19/19 by Julien Perret

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1140 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