I am on Drupal 7 and I have issue. I want to set a token system that will make people buy token from their user account settings in order to be able to do some particular actions on the site.

So I've created three fields in the user's form with the help of Display Suite:

  • field_buy_tickets (Yes/No) : Yes if the user wants to add more tickets. If "Yes", field "field_nb_of_tickets" appears.
  • field_nb_of_tickets : is a list of numbers from 1 to 9 that the user choose one item.
  • field_avoir : When the user Save the changes, the number in the item chosen in "field_nb_of_tickets" should be added to the this field_avoir. I chose this field to be "computed" because I want the new value to be added to the old one, not to override it.

I was sure that it would work well, but I get an error. After a few time trying to make it work, I am still at the same point.

Can somebody help ?

Here are some pictures to illustration the case:

1. The first 2 fields 1. Buy ticket' and Nb of tickets' fields

2. The third field 2. The field Avoir

3. The field_avoir settings 3. field Avoir settings

4. The error 4. The error message

Thank you.

1 Answer 1


Definitely I found out what to do. Maybe this will help somebody else.

  • I wrote this before :

$entity_field[0]["value"] = field_get_items($entity_type, $entity, "field_nb_of_tickets");

  • This is what's new :

I did put the foreign field's value in a variable before adding it to the current field :

$nb_of_tickets= field_get_items($entity_type, $entity, "field_nb_of_tickets");

$entity_field[0]["value"] = $entity_field[0]["value"] + $nb_of_tickets;

Now it works.

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.