Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

Form: GRAV.Yes translation key

Solved by pamtbaau View solution

Started by Duc 4 weeks ago · 2 replies · 238 views
4 weeks ago

My contact form contains a checkbox to agree to our policy before the form can be submitted. Below is email received. How do I change the grav.yes to some other text?

YAML
name: Terri
email: i[email protected]
subject: some subject
country: Barbados
message: some message
privacy: GRAV.YES

I have tried adding the below to my existing en.yaml, but seems to take no affect. Is it not possible to replace the text?

YAML
PLUGIN_FORM:
  DROPZONE_DEFAULT_MESSAGE: Drop your files here
  YES: 'Yes'
  NO: 'No'
last edited 06/16/26 by Duc
4 weeks ago Solution

@duceduc, No, AFAIK, you cannot translate the field tags in a form, only the values.

Here is a workaround...

  • Add the following field to your form as demo
    YAML
    privacy:
        type: toggle
        label: Respect my privacy
        highlight: yes
        help: When enabled, we will respect your privacy
        options:
            yes: PLUGIN_ADMIN.YES
            no: PLUGIN_ADMIN.NO
    
  • Copy the Twig template used to create the email to your own theme.
    NB. Use a custom theme, or child theme, not a theme from GPM.
    Copy user/plugins/form/templates/forms/default/data.html.twig into folder user/themes/yourtheme/templates/forms/default/
  • In your copy, replace line 69 with:
    TWIG
    {% if field.type == 'toggle' %}
      {{ (form.value(scope ~ field.name) == 'yes') ? 'PLUGIN_ADMIN.YES'|t : 'PLUGIN_ADMIN.NO'|t }}
    {% else %}
      {{ string(value)|e|nl2br }}
    {% endif %}
    
  • Create file en.yaml (or your preferred language) in folder /user/languages and add the following:
    TXT
    PLUGIN_ADMIN:
      'YES': Please do
      'NO': I don't bother
    

Your webpage will now look as follows
image|411x167

The email will look as follows:

Name: Yourname
Email: [email protected]
Message: Your message
Respect my privacy: Please do

👍 1
4 weeks ago

@duceduc, If above suggestion did solve your issue, please mark it as "solution". If not, please provide feedback. Others might benefit.

Suggested topics

Topic Participants Replies Views Activity
Support · by BenLaKnet, 5 days ago
1 120 2 days ago
Support · by BenLaKnet, 1 week ago
5 194 2 days ago
Support · by kskt, 2 days ago
0 43 2 days ago
Support · by David Meissner, 2 days ago
0 40 2 days ago
Support · by David Meissner, 3 days ago
3 91 3 days ago