Markdown in form label to add page link

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.

My file form.en.md:

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 [me@somewhere.com](mailto:me@somewhere.com).'
            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: [me@somewhere.com](mailto:me@somewhere.com)

Thanks for your help!
Best regards,
HeliG

1 Like

I think this is a limiation of the current form plugin. Perhaps you can add an issue here: https://github.com/getgrav/grav-plugin-form/issues

Done:

and commited for next release of forms plugin.

3 Likes

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

-    
        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:

<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>

type: checkbox
markdown: true

should be working

Try using markdown remote link in your label

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

20

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?

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.

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

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

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 Like