Enter one thing but save the other I try to construct a field and I wonder how should I implement this process via Field API:


User enter some data to the field. Let's say, the data entered is a node title.
User hits the "Save" button, but what is actually saved in the database is the node ID of the node whose title has been entered by the user. 


Something like this happens with the Entity Reference module: I enter the title of the entity (as I 'm getting assistance through autocomplete), but the module saves target_id, not the title I have actually entered.

How can I gain such behavior?
Create a module for example module name is rose. In that module implement  hook_node_validate

function rose_node_validate($node, $form, &amp;$form_state) {
       //Check to see if this is the node form data you want to change
    if ($form['#form_id'] == 'contentType_node_form') {
        //based on the value provided in 
        $form_state['input']['field_name']['und'][0]['value'];
        $new_info_data = 'some logic'; //get the data you would like to save .
        variable_set('new_info', $new_info_data); //Save the data in a variable.
    }
}


Then implement a hook_node_presave. As per our example

function rose_node_presave($node) {
    //check if the node type is the one you want to change the value
    if ($node-&gt;type == 'content_type') {
        $new_info = variable_get('new_info'); //get the value which was set in validation variable_set()
        $node-&gt;field_name['und'][0]['value'] = $new_info;
    }
}


I have implemented this on Drupal 7. A user enters instagram user name and I get the instagram id from instagram api and save it. Let me know if more explanation is required.

In this implementation users enters only address I get the Lat and Lng based on the address provided and save it in the database.