1

I have some custom profile fields saved on registration in the front end. They are checkboxes and only submit on front end reg when they are set as an array. eg:

<div class="checkbox">
    <label>
        <input type="hidden" name="fields[phoneOptIn]" value="">

        {% set chbox = craft.fields.getFieldByHandle('phoneOptIn').getFieldType.options %}

        {% for option in chbox %}
            <input type="checkbox" name="fields[phoneOptIn][]" value="{{ option.value }}"  tabindex="29">
            {{ option.label }}
        {% endfor %}
    </label>
</div>

"fields[phoneOptIn][]" only works to save with "[]" in name.

The problem in the CP user display is that when configuring to show the check box fields in the CP, the values of the checkboxes are not shown. What is displayed instead is the labels. eg:

labels not values shown in user profile fields in craftcms cp

Is this a bug? Really want to see values in backend not labels.

3
  • I can't tell where your screenshot is from in the CP... is that from a custom plugin? Or maybe an element index page?
    – Brad Bell
    Commented Apr 28, 2017 at 22:12
  • Thats from plain old users view with settings cog used to show checkbox profile fields
    – joomkit
    Commented Apr 29, 2017 at 21:56
  • Any one got an answer as to why the recommended front end format results in lablels not values shown in profile fields in the user panel?
    – joomkit
    Commented May 3, 2017 at 19:55

2 Answers 2

1
+50

This is the expected behaviour. It makes perfect sense to display the human-friendly checkbox label on an admin screen, rather than the (potentially obtuse) checkbox value.

To confirm that this isn't simply an issue with your form, I did the following:

  1. Created a test checkbox field with three options.
  2. Added the test checkbox field to the custom user fields.
  3. Set the checkbox field to display on the users list page.
  4. Edited a user via the control panel, and selected some of the checkbox items.
  5. Returned to the users list page to view the results.

As expected, the users list page displayed the labels of the selected items.

The only difference appears to be that in my installation the selected items are displayed in a single column, as a comma-delimited list, whereas in your example each checkbox item receives its own column.

Here's a screenshot:

Screenshot of the users list

It's also worth mentioning that you are correct in stating that the checkbox option fields need to include the [] in the name. That's exactly how the admin forms work too.

3
  • Thanks Stephen. I have to disagree with this: "It makes perfect sense to display the human-friendly checkbox label on an admin screen" - in my scenario these are single checkboxes and to the admins it makes no sense as they think they are looking at data - you are on every other column. If the values were ones and zeros or more obtuse it might make sense.
    – joomkit
    Commented May 6, 2017 at 18:44
  • Fair enough. If you'd like this to change, you can make a suggestion on the Craft UserVoice. In terms of your original question regarding whether this is a bug, though, no, it's not. Commented May 6, 2017 at 19:10
  • Feature requests have been moved from UserVoice to github.com/craftcms/cms/issues
    – Brad Bell
    Commented Mar 29, 2018 at 17:30
0

Stephen's answer is correct in that it's the default behavior.

You could also write a simple plugin that supplied it's own Checkbox field type that extended Craft's default implementation. It could override the getTableAttributeHtml() method to return the values instead of the labels for element index pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.