in the validation of my form i pass the form_state by reference and I modified the form state value of one of the fields with $form_state['values']['field_total_payment']['und'][0]['value'] = $total_payment;

I also tried form_set_value($form['field_total_payment'], array('und' => array(0 => array('value' => $total_payment))), $form_state);

and I add a second submit to check if the value is there and I can see that with both pieces of code it is in the form_state['value'] , but it is not getting saved to the node.

What is missing for this information to be stored into the database?

  • Have you made sure your form validation function definition is passing $form_state by reference, not by value?
    – Shawn Conn
    Commented Jun 14, 2016 at 0:17
  • Yes it is passing it by reference
    – Diana
    Commented Jun 14, 2016 at 0:55
  • Would be good to post the whole code to have a full picture of the problem.
    – Gulok
    Commented Jun 14, 2016 at 3:07

2 Answers 2



$form_state->setValue($key, $value);

In your case, that should be

$form_state->setValue(['field_total_payment'], $total_payment);
  • no that gives this error "Fatal error: Call to a member function setValue() on array in /Users/dcastillo/Sites/devdesktop/awards-dev/docroot/sites/all/modules/custom/application_editing/application_editing.module on line 291
    – Diana
    Commented Jun 14, 2016 at 13:50
  • I was assuming you are using Drupal 8. However, as your $form_state is an array and not an object, that was probably wrong.
    – Maouna
    Commented Jun 14, 2016 at 14:05

update, i took off the submit handler that i had added to look at the data and it works now.

  • I am not sure if this post completely answers the original question, but glad to see you've figured it out. If you update the question with your submit callback you might get a better answer on what was wrong. Commented Jun 14, 2016 at 15:51

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.