Hi,
I have added a CCK check box field. I want it's default value to be selected. (it should be checked initially when the page is viewed).
But by default the box is unchecked. I tried giving the following code in Php code of 'default value'

return array(0 => array('Default value' => 'on'));

It still does not work. The check box is still unchecked

Any pointers on this issue would be very helpful.

Regards
DrupalDev2007

Comments

mooffie’s picture

Why are you using PHP code?

In the "Default value" fieldset you should see a checkbox you can toggle. Doesn't it appear there?

drupaldev2007’s picture

I selected the checkbox. Now when I create content for the module, the check box is by default not selected. That's why I tried to do it in PHP code. Is there anything fundamental that I am missing.

Any idea would be helpful.

Regards
DrupalDev2007

mooffie’s picture

It should work.

- What exactly did you put in the 'Allowed values list' box?

- What field type are you using? 'Integer'? 'Text'?

- Let's suppose you create a new node. You check the checkbox and submit the node. You now return to the edit screen for this node. Is the checkbox checked? It should be.

- Make sure you're using the most recent (stable) versions of the assorted CCK modules. Parhaps there's a bug in your version.

jweedman’s picture

I've spent about an hour now trying to figure out the same problem as originally mentioned. And what's frustrating, I do not see ANYWHERE where I can input a "Default Value" for a CCK Checkbox field.

It's simply not there. I've tried different themes, updating the module. It's just not there. Any ideas?

Ken Ficara’s picture

When people cite poor documentation as a downside of open source, they aren't kidding. And the vaunted community aspect doesn't always help either.

This is "not a bug," in the sense that the CCK module works that way. Half an hour of web searching revealed what the incomprehensible help text doesn't tell you and the nonexistent documentation doesn't explain. You have to enter this:

0|Label for off
1|Label for on

into the "Allowed values" field. Then your default setting will be respected, and the label will properly show on the form.

1kenthomas’s picture

ANSWER ONE here is that if you have a checkbox field which pre-defines a default setting, once you define the values, save, and there will be a check-box for default. (This will not define default in other cases, so the original question is not answered).

mrtoner’s picture

Unfortunately, too many developers forget that other "normal" people are using their creations and don't create either their product or their documentation for anyone other than themselves or other developers. And when you make suggestions to clean up the documentation or interface, they respond as if you're an idiot.

Thanks for helping me figure out why 1) the label for my CCK checkbox wasn't showing up and 2) why the checkbox wasn't retaining its value.

shecoder’s picture

I have been trying to figure this out for hours. Thanks!!

1kenthomas’s picture

When people cite poor documentation as a downside of open source, they aren't kidding. And the vaunted community aspect doesn't always help either.

I believe that the phenomenon you're citing is that many threads are opened about a subject, but most of them do not have good answers. But think about this for a while, if you will.

This is "not a bug," in the sense that the CCK module works that way. Half an hour of web searching revealed what the incomprehensible help text doesn't tell you and the nonexistent documentation doesn't explain. You have to enter this:

0|Label for off
1|Label for on

into the "Allowed values" field. Then your default setting will be respected, and the label will properly show on the form.

In this case, for a numeric field cast into a checkbox in D6, 'on' will be 1 and the default will be 0. Thus the question is not very well-answered.

jonahan’s picture

0|Label for off
1|Label for on

This worked perfectly, thanks! Without it just like this, the checkbox was defaulting to ON all the time.

Agreed that documentation is spotty, sparse, poor, etc. One of the big drawbacks of going with an open-source, unsupported framework.

As a developer I know it's easy to criticize, but at this point, (what, 8 years into Drupal's development?) you'd think we could put a halt on features and focus on ease-of-use, documentation and whatnot.

ahanchi’s picture

i'm looking for some one to help me about creating a checkbox with multi-columns and multi-rows...i'm trying to put check box in table but i don't get a good result.

thank you for your help.