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:
with the form helper loaded in the head of edit.php like this:
Then I modified the db.xml to add this:
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:
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
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:
with the form helper loaded in the head of edit.php like this:
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']);
Viewing 15 lines of 20 lines. View entire code block.
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
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
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
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!