Problem/Motivation
I was having trouble changing a value while hook_node_validate() so it repopulates the form with the new value I set through form_set_value().
to explain: I validated a form with my module using mymodule_node_validate(). when the submitted form failed a custom check, it should raise an error with form_set_error() and also use different values in some of the fields in the form. now using $form_set_value() (as suggested in the docs) does indeed change the value of the field when it passes the validation, but it does not change the repopulated field of the form.
Proposed resolution
after a lot of debugging, I have found out that drupal uses the values inside $form_state['complete form'], instead of $form_state['values'] to repopulate the form. this actually contradicts the docs and - in my humblest opinion - is not as straight forward as an API should be.
best regards,
alex.
see here for a more use case problem of this.
Comments
Comment #1
lmeurs commentedRan into the same problem with validation on form and field level. I wanted to check a field's value and clean it up a bit. Eventually I ended up with setting the new value in 3 places like this:
I know this is a workaround and not a fix, but so far it seems to be working for me.
Cheers, Laurens