How can I "merge" two fields when a form is submitted?
I would suggest you hook_node_presave() for this. Write this function somewhere in your custom module, just print the $node array. You would found all the fields value there that you can alter accordingly. Your code should be something like this.

function mymodule_node_presave($node) {
  if ($node-&gt;type == 'content type name') {
   // Append last name field value with first name field.
  }
}


This hook function get executed before node_save() that will save your changes in db.