7.x node.api.php hook_node_submit($node, $form, &$form_state)

Act on a node after validated form values have been copied to it.

This hook is invoked when a node form is submitted with either the "Save" or "Preview" button, after form values have been copied to the form state's node object, but before the node is saved or previewed. It is a chance for modules to adjust the node's properties from what they are simply after a copy from $form_state['values']. This hook is intended for adjusting non-field-related properties. See hook_field_attach_submit() for customizing field-related properties.

Parameters

$node: The node object being updated in response to a form submission.

$form: The form being used to edit the node.

$form_state: The form state array.

Related topics

1 function implements hook_node_submit()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

menu_node_submit in modules/menu/menu.module
Implements hook_node_submit().
2 invocations of hook_node_submit()
field_attach_submit in modules/field/field.attach.inc
Perform necessary operations on field data submitted by a form.
node_form_submit_build_node in modules/node/node.pages.inc
Updates the form state's node entity by processing this submission's values.

File

modules/node/node.api.php, line 799
Hooks provided by the Node module.

Code

function hook_node_submit($node, $form, &$form_state) {
  // Decompose the selected menu parent option into 'menu_name' and 'plid', if
  // the form used the default parent selection widget.
  if (!empty($form_state['values']['menu']['parent'])) {
    list($node->menu['menu_name'], $node->menu['plid']) = explode(':', $form_state['values']['menu']['parent']);
  }
}

Comments

webdevfreak’s picture

I have used hook_node_submit() to change the title value of a node.

Node's title gets updated whenever a node is added or updated.

Here is a sample code and full module files can be accessed at https://bitbucket.org/webdevfreak/event-management/src

/**
* Implements hook_node_submit().
*/
function event_management_node_submit($node, $form, &$form_state) {
// Save event name in variable.
$event_name = $form_state['values']['field_event_name']['und'][0]['value'];

// Save event date in variable.
$event_date = $form_state['values']['field_event_date']['und'][0]['value'];

// Save event location in variable.
$event_location = $form_state['values']['field_event_location']['und'][0]['locality'];

// Get day of the week from the event date.
$day_of_week = event_management_day_of_week($event_date);

// Set new event title.
$event_title = $event_name . ' - ' . $day_of_week . ' ' . $event_location;

// Update node title.
$node->title = $event_title;
}