Community Documentation

Making Computed Field work with Flexifield

Last updated June 22, 2011. Created by xstatic on June 22, 2011.
Log in to edit this page.

Many people have stated that Computed Field will not work with Flexifield.

This example shows how to make it work and get a sum of multiple values from a Flexifield's sub-field.
Assuming 'field_my_flexi' is your Flexifield name, and that you have it set to allow multiple entries; and that you have a sub-field called 'field_flexi_price', and you want to get the sum of all prices for that Flexifield...

Computed Code:

$value1 = $node->field_my_flexi[0]['value']['field_flexi_price'][0]['value'];
$value2 = $node->field_my_flexi[1]['value']['field_flexi_price'][0]['value'];
$value3 = $node->field_my_flexi[2]['value']['field_flexi_price'][0]['value'];
$value4 = $node->field_my_flexi[3]['value']['field_flexi_price'][0]['value'];
$node_field[0]['value'] = $value1 + $value2 + $value3 + $value4;

Display Format:

$display = $node_field_item['value'];

Data Type: varchar
Date Length: 5

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers, Site administrators

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.