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

Markdown in form label to add page link

Solved by Andy Miller View solution

Started by Heli 8 years ago · 11 replies · 3823 views
8 years ago

Hi,

I have a similar question to this one:
How can i add anchor link in form label?
The proposed solution was to use HTML, which seems quite ok for an absolute link or an email address, but I'd like to include a relative page link.
As my site is multi language, the easiest option I know of is a markdown relative link, which automatically adds the /cms/en/ part in front of the relative page url (i.e. /legal/privacy).

So, I need either a possibility to "inject" this site base url part including the currently active language to include in an HTML a href tag (then I could use the solution shown in the link above) or, and this I would prefer, I have the option of enabling markdown in form labels.

ContactForm|690x478

My file form.en.md:

TXT
title: 'Contact form'
published: true
process:
    markdown: true
child_type: default
routable: true
cache_enable: true
visible: true
form:
    name: contact
    fields:
        -
            name: name
            label: Name
            placeholder: 'Your Name'
            autofocus: 'on'
            autocomplete: 'on'
            type: text
            validate:
                required: true
        -
            name: email
            label: E-Mail
            placeholder: 'Your eMail address'
            type: email
            validate:
                required: true
        -
            name: message
            label: Message
            placeholder: 'Your message'
            type: textarea
            validate:
                required: true
        -
            name: privacyAccepted
            label: 'I consent that this personal data will be processed according to our [privacy notice](/legal/privacy).'
            type: checkbox
            style: 'float: left; margin-top: 6px;'
            validate:
                required: true
                message: 'Permission to use the given data must be granted!'
        -
            name: privacyDescription
            label: 'You may withdraw this consent at any time via eMail to [[email protected]](mailto:[email protected]).'
            type: display
            markdown: true
            content: null
    buttons:
        -
            type: submit
            value: Submit
        -
            type: reset
            value: Reset
    process:
        -
            email:
                subject: '[somewhere.com Contact form] {{ form.value.name|e }}'
                body: '{% include ''forms/data.html.twig'' %}'
        -
            save:
                fileprefix: contact-
                dateformat: Ymd-His-u
                extension: txt
                body: '{% include ''forms/data.txt.twig'' %}'
        -
            message: ''
        -
            display: thankyou
---

# Contact form

Please describe your concerns, I will answer as soon as possible.  
Direct contact: [[email protected]](mailto:[email protected])

Thanks for your help!
Best regards,
HeliG

👍 1
8 years ago Solution

and commited for next release of forms plugin.

👍 3
8 years ago

Hi! Not working for me. Instead the "type: display" works. Don't know why.
This is my code:

YAML
-    
        name: agree_to_terms
        type: checkbox
        markdown: true
        label: "<a href='http://www.google.it' target='blank'>Accept</a> This is a test of **bold** and _italic_ in a text/display field\n\nanother paragraph...."
        validate:
            required: true

    -
        name: other_terms
        type: display
        size: normal
        markdown: true
        label: Other terms
        content: "<a href='http://www.google.it' target='blank'>Accept!</a> This is a test of **bold** and _italic_ in a text/display field\n\nanother paragraph...."

Tried also to modify checkbox.html.twig file by deleting the escape character for {{ field.label|t|e }} but it changes nothing.

Html output for checkbox label is in commas as seen below:

HTML
<label style="display:inline" class="inline" for="agree_to_terms-"> 
   " href='http://www.google.it' target='blank'>Accept<a> This is a test of <strong>bold</strong> and <em>italic</em> in a text/display fieldb<br /> <br /> another paragraph.... "
   <span class="required">*</span>
</label>
8 years ago

Doesn't work. I tried with o without every kind of commas but the html is rendered in the FE as it is.

20|676x72

8 years ago

It's definitely working.(I'm using exactly the same form definition).
You can use simple markdown links in your form label field. No need for HTML links.
When using markdown links don't use Quotation Marks in your label field!
You have latest form plugin (2.15.0) installed?

last edited 06/13/18 by arank
8 years ago

I had the same issue and it was happening because the custom theme I made used theme inheritance from Quark (version 1.03). The Quark's checkbox.html.twig however wasn't updated yet so that markdown could be enabled for the checkbox. Maybe something similar is going on at your end.

8 years ago

Tried out and doesn't work. I'm running last version of Grav fully updated with Gantry Helium theme.

8 years ago

This seems to work for me with Forms plugin v2.16.3 for checkboxes. It doesn't work for the textarea type, though.

7 years ago

I'm having the same issue as Felix with Forms v 3.0.0, Quark Theme modular page. Markdown is enabled in display and description, but not for label of a checkbox field.

👍 1

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1140 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 138 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 114 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 132 7 months ago