Custom Block checkbox value not saving

Permalink
I've got a custom block that I created the framework for using Jordan Lev's Designer Content. I'm now trying to modify the block so that I can add a checkbox so the user can indicate whether they want the image they chose to be displayed with a lightbox.

The problem is, that no matter what I do, I can't seem to get the checkbox value to be saved to the database... or be re-displayed properly when you edit the block. (the whole block is attached as a ZIP file if that helps)

I've got the field added to the "edit.php" file like this:

<div class="ccm-block-field-group">
   <h2>Lightbox?</h2>
   <?php echo $form->checkbox('field_4_lightbox', 1, 0); ?>
   <?php echo t('Display the Image/Graph in a lightbox pop-up?')?>
</div>


with the form helper loaded in the head of edit.php like this:

<?php  
defined('C5_EXECUTE') or die("Access Denied.");
$al = Loader::helper('concrete/asset_library');
$form = Loader::helper('form');
?>


Then I modified the db.xml to add this:

<field name="field_4_lightbox" type="I1">
   <unsigned />
   <notnull />
   <default value="0" />
</field>


And, finally, I modified the "edit", "view" and "save" functions in the "controller.php" to include the checkbox... although I think this is where my trouble lies:

public function view() {
   $this->set('field_1_wysiwyg_content', $this->translateFrom($this->field_1_wysiwyg_content));
   $this->set('field_2_image', $this->get_image_object($this->field_2_image_fID, 325, 0, false));
   $this->set('field_2_image_full', $this->get_image_object($this->field_2_image_fID, 800, 600, false));
   $this->set('field_3_file', (empty($this->field_3_file_fID) ? null : File::getByID($this->field_3_file_fID)));
   $this->set('field_4_lightbox', (isset($args['field_4_lightbox']) ? 1 : 0));
}
public function edit() {
   $this->set('field_1_wysiwyg_content', $this->translateFromEditMode($this->field_1_wysiwyg_content));
   $this->set('field_2_image', (empty($this->field_2_image_fID) ? null : File::getByID($this->field_2_image_fID)));
   $this->set('field_3_file', (empty($this->field_3_file_fID) ? null : File::getByID($this->field_3_file_fID)));
   $this->set('field_4_lightbox', (isset($args['field_4_lightbox']) ? 1 : 0));
}
public function save($args) {
   $args['field_1_wysiwyg_content'] = $this->translateTo($args['field_1_wysiwyg_content']);


Can anyone see anything glaring that is wrong? I'm assuming it has to do with the way my controller is dealing with the values... but I'm not sure.

If I can't get this to work, I guess I could always just switch to a select field with only two values (Designer Content includes a select option... but not a checkbox).

Thanks!

- John

1 Attachment

arrestingdevelopment
 
kirkroberts replied on at Permalink Reply
kirkroberts
Not sure if this thread is too old to be relevant anymore, but if this is still an issue try removing
$this->set('field_4_lightbox', (isset($args['field_4_lightbox']) ? 1 : 0));

from the view() and edit() functions (just keep it in the save function).

ps - this drove me bonkers the first couple times I tried it, and it's still tricky!
arrestingdevelopment replied on at Permalink Reply
arrestingdevelopment
Thanks! I actually gave up on trying to do the checkbox and just used a Select box instead... Jordan Lev's Designer Content Add-On can create those, so it was a lot easier. A drop-down with "Yes" and "No" options isn't really any harder than a checkbox, so it wasn't any big deal.

But thanks for the follow-up (and the tip). If I come across the need to do a checkbox again, I'll be sure to take your advice.

Thanks!

- John