Custom ajax widget can't save generated value to database - $item always zero
I found multiple examples on how to write your a custom submit handler, but most of them had a flaw in it. They were either always or never called. Sometimes I couldn't access the node_id, which was crucial for me.

I ended up using this:

function b2share_form_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['actions']['submit']['#submit'][] = 'seal_the_deal';
}


function seal_the_deal($form, &amp;$form_state, $entity_id, $entity_type, $form_id) {
 $values = array(
  'url' =&gt; $form_state['values']['b2share_fieldset']['url'],
  'pid' =&gt; $form_state['values']['b2share_fieldset']['pid']
 );

 if ( (empty($values['url'] == false) || (empty($values['pid']) == false)) ) {

    $insert = db_insert('field_data_field_b2share')
     -&gt; fields(array(
        'field_b2share_url' =&gt; $values['url'],
        'field_b2share_pid' =&gt; $values['pid'],
        'entity_id' =&gt; $form_state['node']-&gt;nid,
        'entity_type' =&gt; 'node',
        'bundle' =&gt; $form_state['node']-&gt;type,
        'delta' =&gt; 0,
        'language' =&gt; 'und',
     ))
    -&gt;execute();
     }
   }


Details can be found here:

Custom submit handler is also called when deleting a node

http://atendesigngroup.com/blog/form-altering-node-addedit-forms

Drupal 7 custom form submit handler is not being called