The following function in views/modules/views_profile.inc

/**
 * Display a profile field of type 'checkbox', view as tick mark
 */
function views_handler_field_profile_checkbox($fieldinfo, $fielddata, $value, $data) {
  $value = (unserialize($value) === false) ? $value : unserialize($value);
  return (check_plain($value) == '0') ? '& #10007;' : '& #10003;';
}

attempts to display the checkbox state with specialized Unicode characters:

Unfortunately these characters are not available on normal WinXP computers. Firefox displays question marks and IE displays boxes, and there is no way to distinguish the checked and unchecked states.

It's a cute idea, but even if the characters were available, using the BALLOT X to denote an empty checkbox is a bit misleading, because BALLOT X looks much more like a checked checkbox than an empty one (depending on your visual style).

I'd suggest using this instead:

  return (check_plain($value) == '0') ? '[  ]' : '[X]';

This results in either of

  • [  ]
  • [X]

and it's what the attached patch does — it doesn't look too bad IMO. If you care about accessibility, you'd probably use 'No'/'Yes' instead.

P.S. The PHP filter preserves the &nbsp entity, but not the numeric ones, so I had to fiddle a bit to get the code to display properly. It looks as intended on my FF, but maybe not on your browser...

Comments

salvis’s picture

Title: Checkbox data does not display properly on Thunderbird w/Garland » Checkbox data does not display properly on Windows w/Garland
Assigned: Unassigned » salvis
StatusFileSize
new709 bytes

It turns out that checkbox data is not always set. For example a private profile checkbox field may have no record in the profile_values table, and testing for '0' results in displaying the checkbox as checked when it's not set!

  return (check_plain($value) != '1') ? '[  ]' : '[X]';

gives the correct result.

merlinofchaos’s picture

Does just empty($value) work?

salvis’s picture

We want to display a boolean value, either Checked or Unchecked, I guess. The question is what we do with NULL (no record for that field in the profile_values table). I haven't checked whether check_plain($value) actually returns NULL or an empty string, but we don't want to display three states, do we?

The old code (aside of using non-displayable characters) displayed the Checked token for NULL, which is counter-intuitive, and my code displays the Unchecked token instead.

I would prefer to always have either 0 or 1 in the database, but profile.module doesn't work that way, not even for checkboxes that do appear on the registration form. It could be argued that this is a bug in profile.module, but there are also the private profile fields, and we probably have to accept that these are not set when the registration form is submitted, so we have to deal with NULL.

P.S. You write

If you're CVS updating out of the DRUPAL-5 branch it sometimes lags behind HEAD which is where I work for DRUPAL-5 right now and then sync the branch over.

but you seem to be working on D6 in the MAIN branch now.

merlinofchaos’s picture

That message is quite old. I clearly must update it.

We want to display a boolean value, either Checked or Unchecked, I guess. The question is what we do with NULL (no record for that field in the profile_values table). I haven't checked whether check_plain($value) actually returns NULL or an empty string, but we don't want to display three states, do we?

This is why I suggested empty() -- it will return false for 0, '' and NULL.

salvis’s picture

Ok, I tried

  return empty(check_plain($value)) ? '[  ]' : '[X]';

It gives me

Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in .../views/modules/views_profile.inc on line 259

The line in #1 works just fine...

merlinofchaos’s picture

Ugh, don't check_plain it before running it through empty() -- that's silly. Just empty($value).

salvis’s picture

StatusFileSize
new694 bytes

Yes, that works nicely. :-)

mgifford’s picture

Status: Needs review » Closed (fixed)

I just checked to see if this function exists views_handler_field_profile_checkbox() in D6 or D7. Since it doesn't I'm closing it.