I’m trying to see if a CCK checkbox field is checked.
Is it something like:
if ($node->field_checkbox[0]['value'] = 'checked')
?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can easily check the contents of an object (e.g.
$node) by installing the Devel module and usingdsm($node).In the case of a CCK checkbox,
$node->field_fieldnamecontains an array with at least one element. Each element corresponds to each checked checkbox for the field, and thevaluekey for the checkbox’s element is set to the value you specified in the configuration for the field.Otherwise, if the checkbox is unchecked, it will not appear as an element within
$node->field_fieldname.However, if there are no checkboxes checked,
$node->field_fieldnamewill still contain one element, but thevaluekey for that element will be unset/set toNULL.So, let’s say you had a field,
field_checkbox, with two checkboxes: 1) Foo which has a value offoovalue, and 2) Bar which has a value ofbarvalue.To check if Foo is checked, you might do: