I have three fields in a content type and want to calulate sum of them in another field. First, I use Computed Field but it does not work at all. Then I tried to use conditional field but it is not made for this purpose at all. So I am trying rules module and make an event: After saving new content(or before) - The condition is: Content is of type [something] - The action: Execute custom PHP code.

And the code is:

$field_a = field_get_items($entity_type, $entity, 'field_absence');
$field_b = field_get_items($entity_type, $entity, 'field_delay');
$field_c = field_get_items($entity_type, $entity, 'field_vacation');
[node:field-sum] = $field_a[0]['value']+$field_b[0]['value']+$field_c[0]['value'];

But it does not do anything at all. I used the same code in computed field but it has no result. I'm not an expert Drupal programmer. So I need your helps in it. Thanks in advance.


The Math Field module defines a new field type to dynamically calculate values on entity forms. This is an alternative to Computed Field that does not require the use of PHP Filter.

Note: the above info is an excerpt from its project page.

| improve this answer | |
  • 1
    that was a magic! I appreciate you and the module builder! have a nice day – shekoufeh Jun 25 '15 at 6:06
  • Hm, I'm happy to read that there are "others" who seem to be aware of this (great) Math Field module! +1! – Pierre.Vriens Feb 28 '16 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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