0
votes

I'm learning drupal, working on a module that creates a custom content type. Everything works fine. I can add and update the custom nodes. The only things that's not working is that when I edit the node, the #default_value for the 2 custom fields doesn't display. Here's my hook_form:

function mymodule_form(&$node, $form_state) {
  $type = node_get_types('type', $node);
  $form['title'] = array(
        '#type' => 'textfield',
        '#title' => check_plain($type->title_label),
        '#required' => TRUE,
        '#default_value' => $node->title,
        '#weight' => -5,
    );
    $form['body'] = array(
    '#type' => 'textarea', 
    '#title' => check_plain($type->body_label), 
    '#rows' => 20, 
     '#default_value' => $node->body,
    '#required' => TRUE,
  );
  $form['other'] = array(
    '#type' => 'textfield', 
    '#title' => t('Other thingy'), 
    '#default_value' => $node->other, 
  );
  if ($node->type == 'chucky') {
    $form['other2'] = array(
        '#type' => 'textfield', 
        '#title' => t('Other thingy 2'), 
        '#default_value' => $node->other2, 
      );
  }
  return $form; 
}

So the 2 custom fields are other and other2, those columns are in the mymodule table and I can add and update their values. But they don't get re-displayed as the default values in the edit form.

1

1 Answers

0
votes

sorry, I should've read further in the tutorial I'm following. Apparently, the custom fields aren't part of the node object until you've retrieved them using hook_load(). Works fine now.