Drupal 7. On form validate, I want to:
- check the value of one of the form fields [field-1]
- based on that value, completely remove another field [field-2] together with its values, from the form
If it makes any difference, [field-2] is a multiple-value entity-reference field.
I think I need to do something like --- get hold of $form_state['values']['field_2'] and set it so that it is in the same state it is before any data was entered by the user.
Am I on the right lines? I haven't been able to find examples or documentation on this.
This is what worked for me in the end:
In the submit function (not the validate function):
// Start with a clean array for the field we want to change. $form_state['values']['field_2'] = array(); // Restore the array values that correspond to 'empty' for this field. // In my case this was as follows: $form_state['values']['field_2']['und']['target_id'] = '';