I've installed the Computed Field module following the documentation (enabled the CCK/Content module, then enables Computed Field).

I can add Computed Fields, and set the options, but the fields will never show up on the node/add page. The only HTML rendered is an empty wrapper, i.e.:

<div id="edit-field-id-de-evento" class="form-field-type-computed form-field-name-field-id-de-evento field-widget-computed form-wrapper"></div></code>

I can set up the display on Display Fields, and all the possible values are being shown.

Checking/unchecking "Store value in the database" makes no difference.

No abnormal messages on Drupal logs.

I'm using the module as user 0, so this should be no permissions issues. Maybe I am missing something?

Comments

jorge.suarez’s picture

I've added now some debugging code to see what's happening. All seems normal to me.

function computed_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  syslog(LOG_INFO,"Entered computed_field_field_widget_form");

  // If there are no items yet, add a null item value to avoid
  // preview errors when selecting a different language
  if (empty($items)) $items[0]['value'] = NULL;

  foreach ($items as $item_delta => $item) {
    $element[$item_delta]['value'] = array(
      '#type' => 'value',
      '#tree' => TRUE,
      '#default_value' => isset($item['value']) ? $item['value'] : NULL,
    );
    syslog(LOG_INFO,"computed_field_field_widget_form: {$item_delta}->{$item['value']}");
  }
  return $element;

The syslog output when loading the add/node page or edit is this:

Jun  4 12:40:20 i-5-22-VM apache2: Entered computed_field_field_widget_form
Jun  4 12:40:20 i-5-22-VM apache2: computed_field_field_widget_form: 0->a
Jun  4 12:40:20 i-5-22-VM apache2: computed_field_field_widget_form: 1->b

The provided PHP code was just this:

$entity_field[0]['value'] = "a";
$entity_field[1]['value'] = "b";

So, all seems to be OK. What's wrong? :(

mboeschen’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta1

I am having the exact same issue. Will not display or write to database, even when putting in a direct value.

mboeschen’s picture

Priority: Normal » Major
mboeschen’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Status: Active » Closed (fixed)

I believe I have found the cause:
DO NOT USE <?PHP and ?> in your code!!

cogno’s picture

Status: Closed (fixed) » Needs work

I am also having the same problem. My computed fields don't show up on my node/add form, just the empty wrapper. it *does* show up on the node page itself, however. The calculation and display code I'm using for one of the fields is:

Computed Code:

// field_pickuptotal. It's just field_pickupamount * field_pickupitemprice
// Load the referenced pickupitem node
$total = $entity->field_pickupitemprice[LANGUAGE_NONE][0]['value'] * $entity->field_pickupamount[LANGUAGE_NONE][0]['value'];
$formatted_total = money_format('%i',$total);

$entity_field[0]['value'] = $formatted_total;

Display Code:

$display_output = "$" . $entity_field_item['value'];

Pretty sure I remember it displaying fine on the node/add page before....