How do I alter a field content before saving the form?
You can do it inside a hook_form_alter in a custom module.

function module_name_form_alter(&amp;$form, &amp;$form_state, $form_id){
  if($form_id == 'your-form-id'){
    if(your conditions){ // single or multipe if condtions based on your requirement.
     $value = 'value based on your condition';// your value based on condition.
    }
   $form['your-field-name']['language'][0]['value'] = $value;
  }
}


Hope this will help you