开发者

Drupal: Add two cck fields dynamically and populate third with their sum

I have three cck fields. Let's call them:

  • Field A
  • Field B
  • Field C

I would like Field C to 开发者_运维知识库automatically be populated by the sum of Field A and Field B. That, or the sum to be displayed somewhere within the form.

I guess I could do this using some jQuery, but I'm wondering if there is a Drupal specific way I should do it.

I looked high and low, but I'm still not sure of the best way to do it.

Thanks so much!


You are looking for the Computed Field module. It will allow you to do exactly that.

From the project page:

Computed Field is a very powerful CCK field module that lets you add a custom "computed fields" to your content types. These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it. (Feeling the power yet? :) ) You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views. (Although you should note that Views use requires database stored values.) This field is literally the Swiss Army knife of CCK fields. So start cooking up your PHP based values!

See the documentation for configuration examples and other helpful hints.


You could calculate C from A and B in the node_load() hook ( http://api.drupal.org/api/drupal/modules--node--node.module/function/node_load/6 )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜