Bizarre behavior in checkbox form helper

Permalink
OK, I've learned a lot in the last 24 hours, and things are generally going quite well. However, I've inserted a call to the form helper checkbox utility, and I'm seeing the exact reverse of what I expected.

This is in an external form block. I'm looping through a data array, delivered by $db->getAll, with keys parsed via array_keys. It all works, and now I need to turn a column of 1's and 0's into checkboxes. The code I'm using is:
echo('<td>'.$form->checkbox($key, $row[$key]).'</td>');
// I changed it to the following to show the value for debugging:
echo('<td>'.$form->checkbox($key, $row[$key]).$row[$key].'</td>')


Attached is a screenshot of what I get. It is the exact opposite of what it should be. 0's are displayed as checked, and 1's as unchecked. How is that possible?

1 Attachment

kellymcox
 
JohntheFish replied on at Permalink Reply
JohntheFish
The form helper implements data persistence between calls, so can be very annoying at times (as well as very useful at others).

If you search back through the forums a week or 2 there was quite a bit of discussion on this and some alternatives for getting round it.

I have a hacked version that provides some extra methods to turn persistence off/on and id's off/on (attached).

Its a work in progress, so if you give it a go please evaluate with 2 objectives:
1. That it does not alter the default behaviour and anything else that uses the form helper still works OK.
2. If it solves your problem, or what further adjustments are needed to make it useful.
kellymcox replied on at Permalink Reply
kellymcox
Hey John the Fish!!

Thank you--I really appreciate the quick response. I was so burned out, though, that I had to switch gears . . . then got caught up in another mess! That's finally solved, now back to this issue.

I had seen the discussion about data persistence, but it didn't seem to apply since this was the first call, not the result of a form action or anything. I will review that discussion to see what else I can glean from it.

Meanwhile, can you attach your hack? I don't think it was on your last post . . .

Thanks again!
JohntheFish replied on at Permalink Reply 1 Attachment
JohntheFish
Sorry, what I should have said is that it is attached to the other thread.

Attached it here now.
cryophallion replied on at Permalink Reply
I had the same issue, and I've found a solution, which is posted here:
http://www.concrete5.org/community/forums/customizing_c5/checkbox-f...