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.

General

Configuration to display 'Thank you' in modular contact form

Started by Pedro M 6 years ago · 4 replies · 508 views
6 years ago

Hi.

I'm developing a web with theme Hola, and it's configurated as a modular page, with the contact form in it. I've set the smtp credentials in email plugin, captcha in form plugin, and my .md file and template are correct. The form works correctly.

However, I can't get to show the 'Thank you' page. The form shows a hidden div with the FORM_ALREADY_SUBMITTED when it sent data.

My pages structure is this:
01._home
....
06._contact
contact.es.md
/gracias
formdata.es.md

The formdata.html.twig is in the root folder of the theme (child theme).

The code of my files is this:

YAML
form:
    name: contact-form
    template: form-messages
    refresh_prevention: true
    fields:
        -
            name: Nombre
            label: false
            placeholder: Nombre
            validate:
                required: true
                message: 'Este campo es obligatorio'
            autofocus: 'off'
            autocomplete: 'on'
            type: text
            outerclasses: form-field
            classes: full-width
        -
            name: Email
            label: false
            placeholder: Email
            validate:
                required: true
                message: 'Este campo es obligatorio'
            type: email
            outerclasses: form-field
            classes: full-width
        -
            name: Asunto
            label: false
            type: text
            placeholder: Asunto
            validate:
                required: true
                message: 'Este campo es obligatorio'
            outerClasses: form-field
            classes: full-width
        -
            name: Mensaje
            label: false
            placeholder: Mensaje
            validate:
                required: true
                message: 'Este campo es obligatorio'
            type: textarea
            outerclasses: form-field
            classes: full-width
            rows: null
        -
            g-recaptcha-response: null
            label: Captcha
            type: captcha
            recaptcha_not_validated: '¡Captcha no válido!'
    buttons:
        -
            type: submit
            value: Enviar
            outerclasses: form-field
            classes: 'full-width btn--primary'
    process:
        captcha: true
        save:
            fileprefix: contact-
            dateformat: dmY-His-u
            extension: txt
            body: '{% include ''forms/data.txt.twig'' %}'
        email:
            subject: '[Formulario de juanvillen.es] {{ form.value.name|e }}'
            body: '{% include ''forms/data.html.twig'' %}'
        display: /gracias

Note: (I've tested with display: gracias, without '/')
I don't know where is the fail.
Could help me somebody?

I attach some screenshots:

thankyou1|620x499

Thanks

last edited 02/17/20 by Pedro M
6 years ago

I hope my suggestions are still relevant to you, so here they are.

First try your current solution with the standard Quark theme. If it does work then there is something strange with the Hola theme. If it doesn't work then try to make the thankyou ("gracias") page a child page of your contact form and change display: /gracias to display: gracias. That is like the Example Contact Form.

6 years ago

Hello there,

First of all, thanks for your help. I've made a copy of default.html.twig, from Hola theme, and I've called it gracias.html.twig. After that, I've made a page call Mensaje enviado (sent message) with the content I want to display when someone sends an message from my form.

Finally, in my contact.md page, I've had the following code (only the affected part):

YAML
process:
        captcha: true
        save:
            fileprefix: contact-
            dateformat: dmY-His-u
            extension: txt
            body: '{% include ''forms/data.txt.twig'' %}'
        email:
            subject: '[Formulario de juanvillen.es] {{ form.value.name|e }}'
            body: '{% include ''forms/data.html.twig'' %}'
        reset: true
        display: /gracias

This works correctly, but I with this method I can't show in my gracias.html.twig the results of content sent (with formdata.html.twig).

The code of gracias.html.twig is:

HTML
{% extends 'partials/base.html.twig' %}

{% block content %}
    <section class="small-page-header page-hero" style="background-image:url({{ url('theme://images/default.jpg') }}">
        <div class="row page-header__content narrow text-center">
            <h1 class="page-header__title">
                {{ page.title }}
            </h1>
        </div>
    </section>

    <section id="default" class="s-default">
        <div class="row narrow section-intro">
            <div class="col-full">
                <div>
                    {{ content }}

                </div>
                </div>
            </div>
        </div>
    </section>
{% endblock %}

I hope you help me in that question.

Thanks so much.

6 years ago

I think you need to use the formdata template for your thankyou page.
See the docs on Form Actions and then the section Display.

6 years ago

Thanks,

I'll try it.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 14 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago