CF5 Changing Checkbox Value

kingb 06 May, 2014
Hi All

I'm seeing an odd problem with single checkboxes. I have a form that I use to write new records and edit existing. Everything is working fine and I have "Handle Arrays" before the "DB Save" action. What's odd is that I can write a "1" to the db and the value is returned when editing, however it won't write a "0". I believe CF4 had a "ghost" option. Is something like that needed here or should I look to something else...?

Thanks in advance!
-kevin
GreyHead 06 May, 2014
Hi Kevin,

If checkboxes aren't checked they don't return anything, not even an empty result. If there isn't a ghost option in CFv5 yet then you have a couple of choices. You could use PHPMyAdmin to set a default value of 0 for those columns. Or, you can add a Custom Code action before the DB Save that looks like this:
<?php
if ( !isset($form->data['checkbox_name']) ) {
  $form->data['checkbox_name'] = 0;
}
?>

Bob
kingb 06 May, 2014
Ah! (lightbulb moment).

That works great. I really like the "open-ness" of CF in how it lets one get in there an manipulate and control many aspects throughout the entire process.

Coffee's on me, Cheers!
GreyHead 06 May, 2014
HI Kevin,

I think of ChronoForms as being a bit like a Lego kit - there are some pre-designed kits you can use but you can put the bricks together pretty much any way you like with a bit of experimentation.

Bob
This topic is locked and no more replies can be posted.