Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Displaying a form within a modal

Started by Milind Joshi 9 years ago · 2 replies · 1556 views
9 years ago

Hi,
I am totally new to grav.
I'm trying to display a form within a modal, so, something like this:

YAML
---
title: Portfolio
menu: portfolio
portfolios:
    - title: Home
<Insert form1 here>
      subtitle:
      layout: default
      modalid: 1
      date: 2014-07-18
      img: blah.jpg
      thumbnail: blah.jpg
      alt: image-alt
      projectdate: April 2014
      client: Start Bootstrap
      category: test text
      description: test text
    - title: Auto
<insert form2 here>
      subtitle:
      layout: default
      modalid: 2
      date: 2014-07-17
      img: test2.jpg
      thumbnail: test2.jpg
      alt: image-alt
      projectdate: April 2014
      client: Start Bootstrap
      category: test2
      description: testtext 2

How could I do this?

last edited 07/10/17 by flavio
9 years ago

You wrote modal, I assume you mean "modal" and not "modular", right?

In any way, the concept is the same. Multiple forms can be defined in the page, and then you include the form in your Twig, specifying which form it should display.

In your case, you can define in that page header:

YAML
forms:
    form1:
        fields:
            ...
        buttons:
            ...
        process:
            ...

    form2:
        fields:
            ...
        buttons:
            ...
        process:
            ...

Then add formname in each portfolio item, and enter for example form1. In the portfolio Twig, if portfolio_item is the variable you iterate on, add

{% include "forms/form.html.twig" with { form: forms(portfolio_item.formname) } %}

That should work!

9 years ago

Thank you very much Flavio, I will try this. I think grav is brilliant in its architecture and elegance. I look forward to using, learning, and increasing the adoption of grav!

👍 1

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Anna, 2 days ago
2 51 15 hours ago
Forms & Blueprints · by Anna, 3 days ago
7 81 15 hours ago
Forms & Blueprints · by Anna, 1 week ago
5 185 6 days ago
Forms & Blueprints · by TomW, 1 month ago
3 377 1 month ago
Forms & Blueprints · by Japhy, 2 months ago
2 593 2 months ago