mplodowski / formbuilder-plugin-public

https://octobercms.com/plugin/renatio-formbuilder
https://octobercms.com/plugin/renatio-formbuilder
2 stars 0 forks source link

Use options value in mail templates for checkboxes #51

Closed sqwk closed 1 day ago

sqwk commented 2 months ago

At the moment checkboxes have the value 1. When sending an email this is displayed as label: 1.

Can we use the options array instead to override the displayed text?

Alternatively, is something like this possible?

{% for field in form.getData() %}
    {% if field is same as('checkbox' %}
        {{field.options[field.value]}}
    {% else %}
        **{{ field.label }}:** {{ field.value }}
    {% endif %}
{% endfor %}

For that getDate would also need to supply options and type.

Note that something like the following does not work inside an email template:

{% set form_data = form.getData() %}

{{form_data['field_name'].label}}

Do email templates only support a subset of twig tags?

mplodowski commented 2 months ago

Hi,

I don't understand the issue. What field type are you using?

For simple checkbox options should not be used, because it is simple value.

For checkbox list you can use options and then field.value will display checked options like so:

Checkbox list: Option 1, Option 2

You can export your form and attach it for testing.

sqwk commented 2 months ago

This is about a normal checkbox, which inherently has value 1:

<input id="field_name" name="field_name" class=" form-check-input" value="1" type="checkbox">

In the backend (Form Logs > Form Data tab) this gets translated to Yes or No. In Emails that are sent out it is listed as 0 or 1. Can this 0 or 1 also be translated or customised?

mplodowski commented 2 months ago

Hmm, in the latest version I have also translated value to "Yes" and "No".

Language strings can be override with October.

https://docs.octobercms.com/3.x/extend/system/localization.html#overriding-localization-strings

In renatio/formbuilder/lang/en/lang.php file there is translation:

  'checkbox' => [
      'true' => 'Yes',
      'false' => 'No',
  ],
sqwk commented 1 month ago

Is it possible to override these on a per checkbox basis? Or would this need to be done in the email template?