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

Display additional text under a form

form

Solved by pamtbaau View solution

Started by Sam Neil 4 years ago · 8 replies · 871 views
4 years ago

Hello @all,

I am totally new to GRAV. I have just started a first project and created a form for my website. I used the form plugin, I see the text on the top of the form (the text I can edit with the editor). After the text the form is displayed as it should.

My question: How can I add additional text after the form e.g. a disclaimer or something else.

Best regards
Sam

4 years ago

@sam2105,

You might try the Spacer field (not the best name I must admit) field:

YAML
form:
  name: xyz
  fields:
    name:
      type: text
    test:
      type: spacer
      title: Disclaimer
      text: By submitting this form, your accept our privacy policy ...
      underline: true
  buttons:
    submit:
      type: submiit

Yielding:
image|690x259

4 years ago

Hello pamtbaau,

thank you for your answer. What I meant was to put text under the form, not inside. The text should appear after the submit button and not be part of the form.

Is this possible?

Greetings Sam

4 years ago

@sam2105, You could add a field in the frontmatter of the page and inherit and tweak form.html.twig. Write the value of the field from frontmatter below the output of the form.

Like:

YAML
// form.md
---
myExtraText: This is the text I would like to display below the form.
form:
  name: xyz
  ...
---
TWIG
// form.html.twig: Inherited/overridden from user/plugins/form/form.htm.twig

...
{{ content|raw }}
{% include "forms/form.html.twig" %}

{{ page.header.myExtraText }}
last edited 04/29/22 by pamtbaau
4 years ago

Hello pamtbaau,

thank you very much. This works for me.

Some additional information for everybody facing the same problem. I used the default template and NOT the form template. And in the extended options I have to activate the option processing markdown AND twig.

Greetings Sam

4 years ago

@sam2105, It is a solution, but I'm not sure if it is a proper solution.

Markdown is for content, Twig for layout.

I do not consider a form part of the content and would therefor not use {% include "forms/form.html.twig" %} inside the markdown of default.md.

I would only mix Twig inside Markdown if there is no alternative.

4 years ago

Hello pamtbaau,

as mentioned in my initial post, I am totally new to GRAV.

Where do I have to put this part?

TXT
// form.html.twig: Inherited/overridden from user/plugins/form/form.htm.twig
.
.
.

And if I want the text under the form be formated (strong, h1, etc.) what to do? I have to learn more about twig, markdown and grav 🙂

Thanks for your patience

Sam

4 years ago Solution

@sam2105, First of all, your solution works and will not cause you issues.

However, if you want to go for the extra mile...

  • You'll need a custom theme or an inheriting (aka child) theme. If using a downloaded theme, you will lose your changes when the theme gets updated.
    See Theme Inheritance.
  • Copy file /user/plugins/form/form.htm.twig into /user/mytheme/templates/ and add the following content:
    TWIG
    {{ page.header.myExtraText | markdown }}
    

    The value of field myExtraText will now be processed as Markdown.

  • Add the following Yaml with a Markdown value to the frontmatter of the page:
    YAML
    ---
    ...
    myExtraText: "###Disclaimer\nCompany **Acme Corp** will not accept..."
    ---
    

    Note: In yaml, character # is used to denote comments. Because my sample starts with ###, the string needs to be surrounded by quotes. And since the string contains a newline, double quotes are needed.
    Btw. there are more ways to format long text values in Yaml. See the Yaml specs.

  • Result
    Untitled|664x290
👍 1
last edited 05/01/22 by pamtbaau
4 years ago

Thank you pamtbaau,

this helped me a lot to dive deeper into the structure from GRAV.

Best regards
Sam

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1139 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 137 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 112 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 131 7 months ago