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

Two forms on modular page - how?

form

Started by Oona O'Neil 9 years ago · 6 replies · 859 views
9 years ago

I have two forms on a modular page - a newsletter form and a contact form. I've used form 2.0 plugin and it was working fine when I initially set it up for the contact form, but when I created files for the newsletter everything collapsed. Now the contact form is displaying data (input field 'email' and 'submit' button) of the newsletter form and the newsletter form is not displaying any. Has anyone else experienced a similar problem?

I'm trying to render them by calling the adequate form (as advised here):

Contact Form

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

Newsletter Signup

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

9 years ago

I've tried to follow as advised here about forms on a modular page. However, it's working only if I have one form. If I add the second one, the first is not displaying where it supposed to. It's displayed where the second should be and the second one is not displaying at all.

9 years ago

Where are you forms defined, and what does that look like? Please use code blocks to paste your YAML form definitions.

9 years ago

These are not blueprints, therefore they're not in yaml file. I'm talking about front-end forms, for example contact form. I see some common confusion here, perhaps there should be more distinction between one and another.

9 years ago

Frontend forms are defined in YAML frontmatter of the page just like a back end blueprint. Here's an example I have lying around:

TWIG
---
menu: Columns Test
cache_enable: false
form:
    name: columns-form
    refresh_prevention: false

    fields:
        columns:
            type: columns

            fields:
                column0:
                    type: column

                    fields:
                        firstname:
                            label: FIRSTNAME
                            default: FIRSTNAME_PLACEHOLDER
                            autocomplete: on
                            type: text
                            validate:
                                required: true

                column1:
                    type: column

                    fields:
                        lastname:
                            label: SURNAME
                            default: SURNAME_PLACEHOLDER
                            autocomplete: on
                            type: text
                            validate:
                                required: true
    buttons:
        submit:
            type: submit
            value: SUBMIT
    process:
        save:
            fileprefix: contact-
            dateformat: Ymd-His-u
            extension: csv
            body: "{% include 'forms/data.txt.twig' %}"
            operation: create
        message: 'Success!'
        display: '/form/landing'
---

# Contact
👍 1
9 years ago

Thanks, now I just need to remove the loop in the html.twig file and it should work.

9 years ago

I've actually didn't have to remove the loop. Just inspected the classes and changed css.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 85 13 hours ago
General · by pamtbaau, 18 hours ago
1 60 17 hours ago
General · by Andy Miller, 1 day ago
0 47 1 day ago
General · by Marcel, 12 months ago
6 350 5 days ago
General · by Duc , 6 days ago
3 44 5 days ago