How do I retrieve saved checkbox values from a field using the FormAPI?

The form/node saves successfully, and when I look in the DB, the data was successively saved in the 'field_data_field_test' table, but I can't figure out how to pull that back out and apply the 'checked' status using #default_value.

$form['field_test']['und']['#default_value'] = $How_Can_I_Get_This_Data_From_DB

Is there a function I can use to retrieve checked values for a given field within a given node? I'm trying to avoid direct queries. :)


Ended up using

function _get_review_site_defaults() {
    $query = new EntityFieldQuery;
    global $user;
    $result = $query
            ->entityCondition('entity_type', 'node', '=')
            ->entityCondition('bundle', 'field_test', '=')
            ->propertyCondition('uid', $user->uid, '=')
            ->propertyCondition('status', 1)
    if (count($result) == 0) {
        $defaults = array(1);
    } else {
        $entities = entity_load('node', array_keys($result['node']));
        foreach ($entities as $key => $value) {
            if ($value->field_default_field_test[$value->language][0]['value'] == 'Yes') {
                $defaults[] = $value->nid;
    return $defaults;
  • Drupal 6 or 7??
    – iStryker
    Jul 12, 2011 at 6:16
  • Drupal Seven (7)
    – Citricguy
    Jul 13, 2011 at 0:08
  • 1
    if you solve your own answer, please post it as an answer
    – iStryker
    Jul 20, 2011 at 20:40

1 Answer 1


after you save it, it saves the value of the checkbox as #value (not #default_value).

When defining the field settings: (pulled from D7 cck_table.module)

  $form['css_class'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS Class'),
    '#description' => t('Specify a class to be added to the table element.'),
    **'#default_value' => isset($field['css_class']) ? $field['css_class'] : '',**


More likely you would want to do this:

If you want to grab the default values, you can call `field_info_field($field_name

Returns data about an individual field, given a field name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.