So these are my functions:
function mycustom_form_alter(&$form, &$form_state, $form_id) {
$form['actions']['submit']['#submit'][] = 'b2share_form_submit';
return $form;
}
I can also attach the custom submit handler in other ways to the form, but only this way I can still access the nid and the bundle of the node.
function b2share_form_submit($form, &$form_state, $entity_id, $entity_type) {
$values = array(
'url' => $form_state['values']['b2share_fieldset']['url'],
'pid' => $form_state['values']['b2share_fieldset']['pid']
);
if ( (empty($values['url'] == false) || (empty($values['pid']) == false)) ) {
$insert = db_insert('field_data_field_b2share')
-> fields(array(
'field_b2share_url' => $values['url'],
'field_b2share_pid' => $values['pid'],
'entity_id' => $form_state['node']->nid,
'entity_type' => 'node',
'bundle' => $form_state['node']->type,
'delta' => 0,
'language' => 'und',
))
->execute();
}
}
I can add nodes and edit them perfectly, but whenever I try to delete one, the custom handler function is called and prevent drupal from doing anything. No error messages, nothing in the logs.
Can someone help?
hook_form_alter
passes the form by reference (notice the ampersand in&$form
) and therefor you should not return the $form variable.