Welcome Guest, Not a member yet? Register   Sign In
Why isn't set_checkbox working for me?
#1

[eluser]Unknown[/eluser]
Hi everyone,

I'll admit up-front that I'm very new to CodeIgniter.

I'm creating a set of checkboxes in my PyroCMS admin page using CodeIgniter's form_checkbox and set_checkbox functions:

Code:
<?php echo form_checkbox('purpose_e', '1', set_checkbox('purpose_e', '1')); ?> Environmental
<?php echo form_checkbox('purpose_f', '1', set_checkbox('purpose_f', '1')); ?> Flood
<?php echo form_checkbox('purpose_g', '1', set_checkbox('purpose_g', '1')); ?> Groundwater
<?php echo form_checkbox('purpose_h', '1', set_checkbox('purpose_h', '1')); ?> Hydropower
<?php echo form_checkbox('purpose_i', '1', set_checkbox('purpose_i', '1')); ?> Irrigation
<?php echo form_checkbox('purpose_n', '1', set_checkbox('purpose_n', '1')); ?> Navigation
<?php echo form_checkbox('purpose_p', '1', set_checkbox('purpose_p', '1')); ?> Pollution

Everything seems to work fine, the page executes and the relevant 1 values are written to the database fields, but when I edit the entry the relevant checkboxes aren't being rechecked, I just get a set of blank unchecked boxes.

Is there some elementary mistake I'm making?

Thanks in advance for any help,
Tony.
#2

[eluser]CroNiX[/eluser]
Yes, set_checkbox() is only for if you are manually writing the html checkbox form element. You are using the form helper to generate your checkboxes. Try using set_value(). The 2nd value for the default should be a boolean, like TRUE/FALSE, not a string like '1'.
#3

[eluser]Aken[/eluser]
I touched on this a while back, maybe it will help you: http://ellislab.com/forums/viewthread/194556/




Theme © iAndrew 2016 - Forum software by © MyBB