2

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.

1 Answer 1

2

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.

3
  • 1
    that was a magic! I appreciate you and the module builder! have a nice day
    – shekoufeh
    Jun 25, 2015 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! Feb 28, 2016 at 10:38
  • In the Drupal 7 rules 2 actions there, under Data, is "Calculate a value." I've been searching for days and cannot find one single example of how that field works. Can you provide an answer that uses that selector?
    – blue928
    Sep 13, 2021 at 21:32

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.