Custom PHP to add 1 to a CCK number field?

Events happening in the community are now at Drupal community events on www.drupal.org.
joecanti's picture

Hi all,

Please could someone help me - I am trying to insert a bit of custom php into an action so that when triggered, 1 is added to a CCK numerical field.

Below is a jpeg of where I've got to so far - the problem is it keeps refreshing the CCK field with the number and not adding it on:

(In the example I was trying to add 5)

http://avocet-designs.co.uk/populate_rules.jpg

The content type is called 'track' and the field is called 'plusvote'.

The idea is that when a Flag is activated on a 'track', a rule is triggered and a vote (+1) is added to the CCK 'plusvote' field

Should be fairly simple but I just cant get it to function...

Any help much appreciated,

cheers, Joe

Comments

Try the Rules module

thomas4019's picture

It is much more powerful than actions/triggers and allows custom PHP and setting CCK fields easily.

Thomas Hansen
www.ThomasHansen.me

Your rule seems fine...

itangalo's picture

Have you checked that it is actually executed? Turning on the messages at rules -> settings has helped me many times...

//Johan Falk, NodeOne, Sweden

Thanks for the reply and the

joecanti's picture

Thanks for the reply and the tip...

This is what it spits out:

      o 0 ms "A node has been flagged, under "Vote Here"" has been invoked.
      o 0.813 ms Executing the rule "Plusvote" on rule set "A node has been flagged, under "Vote Here""
      o 0.971 ms Loaded variable "flagged content"
      o 30.762 ms Action execution: "Populate flagged content's field 'field_plusvote'"
      o 30.932 ms Saved variable flagged content of type node.
      o 73.556 ms Evaluation of "A node has been flagged, under "Vote Here"" has been finished.
* Thanks for Voting!

It looks like it works well, but it's like it wipes the field then replaces it with the + value rather than taking the initial field value and adding to it...?

Maybe I'm using the wrong type of rule? Many thanks, Joe

One node too many?

itangalo's picture

In the debug information it seems that you are loading the flagged node manually. This shouldn't be necessary -- it is already loaded -- and could cause some confusion when two identical nodes are saved. (I imagine that the copy that you haven't changed might be saved last, thereby wiping out any changes you made...)

Check if there isn't already a node object available, probably under the name flagged node. If so, run your 'populate CCK field' action on that node instead.

Good luck!
//Johan Falk, NodeOne, Sweden

hey can you post how you did

2by's picture

hey can you post how you did this, i am kinda trying to the same through rules and cck, only issue i am having is +1 ing the value of the given cck field,

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: