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

Two column form layout - possible?

Solved by Oona O'Neil View solution

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

I need to create two forms on a modular page - one is a newsletter subscription and second is a contact form. As I understand I have to create a form.md file in each modular folder (_newsletter, _contact).

What about corresponding .html.twig files, how do I call them?

Is it doable with the Form plugin?

9 years ago Solution

I've made it work thanks to this post: /forum/archive/modular-forms-t7417

Now wondering if it's possible to change the layout of the contact form so two input fields (name and email) would be in one column on the left side and one bigger (message) would be on the right side.

9 years ago

I've solved the initial problem. Please look to my next comment for solution and another problem I've encountered (therefore edited the title of this post).

9 years ago

The form plugin actually already has a column and columns fields and you use them just like in the admin:

YAML

  fields:

    columns:
      type: columns

      fields:

        column1:
          type: column
          fields:

            field1:
              type: text
              label: Field 1

        column2:
          type: column
          fields:

            field2:
              type: text
              label: Field 2
...
9 years ago

OK, I thought it was only possible when creating blueprints, not in the front-end of the website. Let me give it a try, thanks!
PS
Any advise how to render it later on in Twig files? I have a problem with calling data which is too nested, will it be: {{fields.column1.type}}?

9 years ago

I've used your advice, but something is still not working as now only one column is displayed (before I had one row of three fields). Would you mind having a look at my code?

YAML
forms:
contact_form:
    name: contact
    action: /home
    fields:

        columns:
            type: columns

            fields:

                    column1:
                        type: column
                        fields:

                            - name: name
                              placeholder: Name
                              type: text
                              validate:
                                required: true
                              classes: contact__form__input
                            - name: email
                              placeholder: Email
                              type: email
                              validate:
                                required: true
                              classes: contact__form__input

                    column2:
                        type: column
                        fields:

                            - name: message
                              placeholder: Message
                              type: textarea
                              size: long
                              validate:
                                required: true
                              classes: contact__form__input--lg
8 years ago

@rhuk wow! Thank you so much. This option was exactly what I needed, but I couldn't find it anywhere in the docs - is that right? So how could I know about this in the first place - without meeting nice and helpful people like you?

@OonaONeil you probably found your solution by now, I guess. But for other readers who joined the party later - like I did - it is a matter of addressing the differently generated HTML code for two columns with corresponding CSS rules.

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1136 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 134 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 129 7 months ago