Drupal Association members fund grants that make connections all over the world.
I have a custom content type and trying to alter its node form. The form has two fields, field1 and field 2. Either field1 or field 2 is visible to the user (based on user role). The goal is to let a user enter a value in one (visible) field and to calculate the value of the other (hidden) field, so that both values could be saved to the db. For instance, as in converting kilograms to pounds - the user enters the value in one field, then the second value is saved to the db after the calculation is performed. I am ok with doing form_hook_alter and have been using hook_node_presave to calculate the values. It works, but the problem is that I have to make the fields required or the users simply do not enter the data. Since I have to make both fields required, the hidden field has to be populated with the result of the calculation BEFORE the form validation stage and hook_node_presave functions after the validation is done, so the form never passes validation with required fields and never gets to the calculation. I tried a few different ways, but with no success. Is it possible to populate field values with other values, in this case a calculated value based on the value of another field, after submit and before validation? Do I need to mod $form_state['values'] array? There must be a simple way to do it!